hytos / DTI_PID / ID2PSN / DB.cs @ 88c1965b
이력 | 보기 | 이력해설 | 다운로드 (181 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Data; |
4 |
using System.Data.Common; |
5 |
using System.Data.SqlClient; |
6 |
using System.Data.SQLite; |
7 |
using System.Linq; |
8 |
using System.Text.RegularExpressions; |
9 |
|
10 |
namespace ID2PSN |
11 |
{ |
12 |
public class DB |
13 |
{ |
14 |
const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE"; |
15 |
const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING"; |
16 |
const string PSN_VENTDRAIN_SETTING = "T_PSN_VENTDRAIN_SETTING"; |
17 |
const string PSN_VIEW = "T_PSN_VIEW"; |
18 |
const string PSN_TRANSFORMKEYWORD_SETTING = "T_PSN_TRANSFORMKEYWORD_SETTING"; |
19 |
const string PSN_VALVEGROUP_SETTING = "SPPIDValveGroup"; |
20 |
|
21 |
const string PSN_PATHITEMS = "SPPIDPathItem"; |
22 |
const string PSN_SEQUENCEDATA = "SPPIDSequenceData"; |
23 |
const string PSN_PIPESYSTEMNETWORK = "SPPIDPipeSystemNetwork"; |
24 |
const string PSN_EQUIPMENT = "SPPIDEquipment"; |
25 |
const string PSN_NOZZLE = "SPPIDNozzle"; |
26 |
const string PSN_FLUIDCODE = "SPPIDFluidCode"; |
27 |
const string PSN_PIPINGMATLCLASS = "SPPIDPipingMatlClass"; |
28 |
const string PSN_TOPOLOGYSET = "SPPIDTopologySet"; |
29 |
//2021.11.17 추가 |
30 |
const string PSN_PIPELINE = "SPPIDPipeLine"; |
31 |
//2021.11.26 추가 |
32 |
const string PSN_INSULATIONPURPOSE = "SPPIDInsulationPurpose"; |
33 |
//2022.01.12 추가 //ARS_COMMON DB |
34 |
const string PSN_REVISION = "PSNRevision"; |
35 |
const string PSN_COMMON = "ARS_COMMON"; |
36 |
//2022.01.19 추가 |
37 |
const string PSN_PIPESYSTEM = "SPPIDPipeSystem"; |
38 |
|
39 |
//2022.02.03 추가 |
40 |
const string PSN_NOPOCKETSETTING = "T_PSN_NOPOCKET_SETTING"; |
41 |
/// <summary> |
42 |
/// ID2 Project.db 데이터를 가져온다. |
43 |
/// DB 접속 정보 및 DBType (Sqlite, Mssql) 정보를 가져옴 |
44 |
/// - JY |
45 |
/// </summary> |
46 |
/// <returns></returns> |
47 |
public static DataTable GetProject() |
48 |
{ |
49 |
DataTable dt = new DataTable(); |
50 |
ID2Info id2Info = ID2Info.GetInstance(); |
51 |
try |
52 |
{ |
53 |
using (SQLiteConnection connection = new SQLiteConnection(@"Data Source = C:\ProgramData\Digital PID\Project.db", true)) |
54 |
{ |
55 |
connection.Open(); |
56 |
if (connection.State.Equals(ConnectionState.Open)) |
57 |
{ |
58 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
59 |
{ |
60 |
cmd.CommandText = "SELECT p.[Id], p.Name, p.Path, s.DBTypes_UID, s.Host, s.[User], s.[Password], s.FilePath FROM DBSettings s, Projects p WHERE s.Projects_UID = p.[Id]"; |
61 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
62 |
dt.Load(dr); |
63 |
} |
64 |
|
65 |
} |
66 |
connection.Close(); |
67 |
} |
68 |
} |
69 |
catch (Exception ex) |
70 |
{ |
71 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
72 |
} |
73 |
|
74 |
dt.AcceptChanges(); |
75 |
dt.DefaultView.Sort = "Name"; |
76 |
dt = dt.DefaultView.ToTable(); |
77 |
|
78 |
return dt; |
79 |
} |
80 |
|
81 |
/// <summary> |
82 |
/// SQLite에 초기 DB 생성 |
83 |
/// - JY |
84 |
/// </summary> |
85 |
/// <returns></returns> |
86 |
public static bool ConnTestAndCreateTable() |
87 |
{ |
88 |
bool result = false; |
89 |
ID2Info id2Info = ID2Info.GetInstance(); |
90 |
|
91 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
92 |
{ |
93 |
try |
94 |
{ |
95 |
var names = connection.GetTableNames(); |
96 |
var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING); |
97 |
Dictionary<string, string> dicColCheck = new Dictionary<string, string>(); |
98 |
dicColCheck.Add("GROUP_ID", "TEXT"); |
99 |
dicColCheck.Add("DESCRIPTION", "TEXT"); |
100 |
dicColCheck.Add("INDEX", "INTEGER"); |
101 |
dicColCheck.Add("NAME", "TEXT"); |
102 |
|
103 |
if (matched == null) |
104 |
{ |
105 |
var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)"; |
106 |
using (var cmd = connection.GetSqlStringCommand(query)) |
107 |
{ |
108 |
cmd.ExecuteNonQuery(); |
109 |
} |
110 |
} |
111 |
else |
112 |
{ |
113 |
AddColumn(PSN_HEADER_SETTING, dicColCheck); |
114 |
} |
115 |
|
116 |
matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING); |
117 |
dicColCheck.Clear(); |
118 |
dicColCheck.Add("GROUP_ID", "TEXT"); |
119 |
dicColCheck.Add("DESCRIPTION", "TEXT"); |
120 |
dicColCheck.Add("INDEX", "INTEGER"); |
121 |
dicColCheck.Add("NAME", "TEXT"); |
122 |
if (matched == null) |
123 |
{ |
124 |
var query = $"CREATE TABLE {PSN_VENTDRAIN_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)"; |
125 |
using (var cmd = connection.GetSqlStringCommand(query)) |
126 |
{ |
127 |
cmd.ExecuteNonQuery(); |
128 |
} |
129 |
} |
130 |
else |
131 |
{ |
132 |
AddColumn(PSN_VENTDRAIN_SETTING, dicColCheck); |
133 |
} |
134 |
|
135 |
matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE); |
136 |
dicColCheck.Clear(); |
137 |
dicColCheck.Add("UID", "TEXT"); |
138 |
if (matched == null) |
139 |
{ |
140 |
var query = $"CREATE TABLE {PSN_TOPOLOGY_RULE} (UID TEXT)"; |
141 |
using (var cmd = connection.GetSqlStringCommand(query)) |
142 |
{ |
143 |
cmd.ExecuteNonQuery(); |
144 |
} |
145 |
|
146 |
DataTable topologyRule = new DataTable(); |
147 |
topologyRule.Columns.Add("NAME", typeof(string)); |
148 |
|
149 |
topologyRule.Rows.Add("FluidCode"); |
150 |
topologyRule.Rows.Add("-"); |
151 |
topologyRule.Rows.Add("PipingMaterialsClass"); |
152 |
topologyRule.Rows.Add("-"); |
153 |
topologyRule.Rows.Add("Tag Seq No"); |
154 |
|
155 |
SaveTopologyRule(topologyRule); |
156 |
} |
157 |
//else |
158 |
//{ |
159 |
// AddColumn(PSN_TOPOLOGY_RULE, dicColCheck); |
160 |
//} |
161 |
|
162 |
matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK); |
163 |
dicColCheck.Clear(); |
164 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
165 |
dicColCheck.Add("Type", "NVARCHAR(255)"); |
166 |
dicColCheck.Add("OrderNumber", "NVARCHAR(255)"); |
167 |
dicColCheck.Add("Pipeline_OID", "NVARCHAR(255)"); |
168 |
dicColCheck.Add("From_Data", "NVARCHAR(255)"); |
169 |
dicColCheck.Add("To_Data", "NVARCHAR(255)"); |
170 |
dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(125)"); |
171 |
dicColCheck.Add("PSNRevisionNumber", "NVARCHAR(255)"); |
172 |
dicColCheck.Add("IsValid", "INT"); |
173 |
dicColCheck.Add("Status", "NVARCHAR(255)"); |
174 |
dicColCheck.Add("PBS", "NVARCHAR(255)"); |
175 |
dicColCheck.Add("Drawings", "NVARCHAR(255)"); |
176 |
dicColCheck.Add("IncludingVirtualData", "NVARCHAR(10)"); |
177 |
dicColCheck.Add("PSNAccuracy", "REAL"); |
178 |
|
179 |
if (matched == null) |
180 |
{ |
181 |
var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(255), Type NVARCHAR(255), OrderNumber NVARCHAR(255), Pipeline_OID NVARCHAR(255), From_Data NVARCHAR(255), " + |
182 |
"To_Data NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), IsValid INTEGER, Status NVARCHAR(255), PBS NVARCHAR(255), Drawings NVARCHAR(255), " + |
183 |
"IncludingVirtualData NVARCHAR(10), PSNAccuracy REAL)"; |
184 |
using (var cmd = connection.GetSqlStringCommand(query)) |
185 |
{ |
186 |
cmd.ExecuteNonQuery(); |
187 |
} |
188 |
} |
189 |
else |
190 |
{ |
191 |
AddColumn(PSN_PIPESYSTEMNETWORK, dicColCheck); |
192 |
} |
193 |
|
194 |
matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT); |
195 |
dicColCheck.Clear(); |
196 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
197 |
dicColCheck.Add("ItemTag", "NVARCHAR(255)"); |
198 |
dicColCheck.Add("Xcoords", "REAL"); |
199 |
dicColCheck.Add("Ycoords", "REAL"); |
200 |
if (matched == null) |
201 |
{ |
202 |
var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL)"; |
203 |
using (var cmd = connection.GetSqlStringCommand(query)) |
204 |
{ |
205 |
cmd.ExecuteNonQuery(); |
206 |
} |
207 |
} |
208 |
else |
209 |
{ |
210 |
AddColumn(PSN_EQUIPMENT, dicColCheck); |
211 |
} |
212 |
|
213 |
dicColCheck.Clear(); |
214 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
215 |
dicColCheck.Add("ItemTag", "NVARCHAR(255)"); |
216 |
dicColCheck.Add("Xcoords", "REAL"); |
217 |
dicColCheck.Add("Ycoords", "REAL"); |
218 |
dicColCheck.Add("Equipment_OID", "NVARCHAR(255)"); |
219 |
dicColCheck.Add("Fluid", "NVARCHAR(255)"); |
220 |
dicColCheck.Add("NPD", "NVARCHAR(255)"); |
221 |
dicColCheck.Add("PMC", "NVARCHAR(255)"); |
222 |
dicColCheck.Add("Rotation", "REAL"); |
223 |
dicColCheck.Add("FlowDirection", "NVARCHAR(255)"); |
224 |
|
225 |
matched = names.FirstOrDefault(param => param == PSN_NOZZLE); |
226 |
if (matched == null) |
227 |
{ |
228 |
var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL, Equipment_OID NVARCHAR(255), " + |
229 |
"Fluid NVARCHAR(255), NPD NVARCHAR(255), PMC NVARCHAR(255), Rotation REAL, FlowDirection NVARCHAR(255))"; |
230 |
using (var cmd = connection.GetSqlStringCommand(query)) |
231 |
{ |
232 |
cmd.ExecuteNonQuery(); |
233 |
} |
234 |
} |
235 |
else |
236 |
{ |
237 |
AddColumn(PSN_NOZZLE, dicColCheck); |
238 |
} |
239 |
|
240 |
matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE); |
241 |
dicColCheck.Clear(); |
242 |
dicColCheck.Add("UID", "NVARCHAR(50)"); |
243 |
dicColCheck.Add("Code", "NVARCHAR(255)"); |
244 |
dicColCheck.Add("Description", "NVARCHAR(255)"); |
245 |
dicColCheck.Add("Condition", "NVARCHAR(255)"); |
246 |
dicColCheck.Add("Remarks", "NVARCHAR(255)"); |
247 |
dicColCheck.Add("GroundLevel", "NVARCHAR(20)"); |
248 |
if (matched == null) |
249 |
{ |
250 |
var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))"; |
251 |
using (var cmd = connection.GetSqlStringCommand(query)) |
252 |
{ |
253 |
cmd.ExecuteNonQuery(); |
254 |
} |
255 |
} |
256 |
else |
257 |
{ |
258 |
AddColumn(PSN_FLUIDCODE, dicColCheck); |
259 |
} |
260 |
|
261 |
matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS); |
262 |
dicColCheck.Clear(); |
263 |
dicColCheck.Add("UID", "NVARCHAR(50)"); |
264 |
dicColCheck.Add("Priority", "INTEGER"); |
265 |
dicColCheck.Add("Code", "NVARCHAR(255)"); |
266 |
dicColCheck.Add("Description", "NVARCHAR(255)"); |
267 |
dicColCheck.Add("Condition", "NVARCHAR(255)"); |
268 |
dicColCheck.Add("Remarks", "NVARCHAR(255)"); |
269 |
dicColCheck.Add("GroundLevel", "NVARCHAR(20)"); |
270 |
if (matched == null) |
271 |
{ |
272 |
var query = $"CREATE TABLE {PSN_PIPINGMATLCLASS} (UID NVARCHAR(50), Priority INTEGER, Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))"; |
273 |
using (var cmd = connection.GetSqlStringCommand(query)) |
274 |
{ |
275 |
cmd.ExecuteNonQuery(); |
276 |
} |
277 |
} |
278 |
else |
279 |
{ |
280 |
AddColumn(PSN_PIPINGMATLCLASS, dicColCheck); |
281 |
} |
282 |
|
283 |
matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA); |
284 |
dicColCheck.Clear(); |
285 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
286 |
dicColCheck.Add("SERIALNUMBER", "NVARCHAR(255)"); |
287 |
dicColCheck.Add("PathItem_OID", "NVARCHAR(255)"); |
288 |
dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(255)"); |
289 |
if (matched == null) |
290 |
{ |
291 |
var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(255), SERIALNUMBER NVARCHAR(255), PathItem_OID NVARCHAR(255), TopologySet_OID_Key NVARCHAR(255))"; |
292 |
using (var cmd = connection.GetSqlStringCommand(query)) |
293 |
{ |
294 |
cmd.ExecuteNonQuery(); |
295 |
} |
296 |
} |
297 |
else |
298 |
{ |
299 |
AddColumn(PSN_SEQUENCEDATA, dicColCheck); |
300 |
} |
301 |
|
302 |
matched = names.FirstOrDefault(param => param == PSN_PATHITEMS); |
303 |
dicColCheck.Clear(); |
304 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
305 |
dicColCheck.Add("SequenceData_OID", "NVARCHAR(255)"); |
306 |
dicColCheck.Add("TopologySet_OID", "NVARCHAR(255)"); |
307 |
dicColCheck.Add("BranchTopologySet_OID", "NVARCHAR(255)"); |
308 |
dicColCheck.Add("PipeLine_OID", "NVARCHAR(255)"); |
309 |
dicColCheck.Add("ItemName", "NVARCHAR(255)"); |
310 |
dicColCheck.Add("ItemTag", "NVARCHAR(255)"); |
311 |
dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)"); |
312 |
dicColCheck.Add("CLASS", "NVARCHAR(255)"); |
313 |
dicColCheck.Add("SUBCLASS", "NVARCHAR(255)"); |
314 |
dicColCheck.Add("TYPE", "NVARCHAR(255)"); |
315 |
dicColCheck.Add("PIDNAME", "NVARCHAR(255)"); |
316 |
dicColCheck.Add("Equipment_OID", "NVARCHAR(255)"); |
317 |
dicColCheck.Add("NPD", "NVARCHAR(255)"); |
318 |
dicColCheck.Add("GROUPTAG", "NVARCHAR(255)"); |
319 |
dicColCheck.Add("PipeSystemNetwork_OID", "NVARCHAR(255)"); |
320 |
dicColCheck.Add("PipeRun_OID", "NVARCHAR(255)"); |
321 |
dicColCheck.Add("ViewPipeSystemNetwork_OID", "NVARCHAR(255)"); |
322 |
|
323 |
if (matched == null) |
324 |
{ |
325 |
var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(255), SequenceData_OID NVARCHAR(255), " + |
326 |
"TopologySet_OID NVARCHAR(255), BranchTopologySet_OID NVARCHAR(255), PipeLine_OID NVARCHAR(255), ItemName NVARCHAR(255), ItemTag NVARCHAR(255), DESCRIPTION NVARCHAR(255), " + |
327 |
"CLASS NVARCHAR(255), SUBCLASS NVARCHAR(255), TYPE NVARCHAR(255), PIDNAME NVARCHAR(255), Equipment_OID NVARCHAR(255), NPD NVARCHAR(255), GROUPTAG NVARCHAR(255), PipeSystemNetwork_OID NVARCHAR(255), PipeRun_OID NVARCHAR(255), " + |
328 |
"ViewPipeSystemNetwork_OID NVARCHAR(255))"; |
329 |
using (var cmd = connection.GetSqlStringCommand(query)) |
330 |
{ |
331 |
cmd.ExecuteNonQuery(); |
332 |
} |
333 |
} |
334 |
else |
335 |
{ |
336 |
AddColumn(PSN_PATHITEMS, dicColCheck); |
337 |
} |
338 |
|
339 |
matched = names.FirstOrDefault(param => param == PSN_VIEW); |
340 |
dicColCheck.Clear(); |
341 |
dicColCheck.Add("OID", "TEXT"); |
342 |
if (matched == null) |
343 |
{ |
344 |
var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)"; |
345 |
using (var cmd = connection.GetSqlStringCommand(query)) |
346 |
{ |
347 |
cmd.ExecuteNonQuery(); |
348 |
} |
349 |
} |
350 |
|
351 |
matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET); |
352 |
dicColCheck.Clear(); |
353 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
354 |
dicColCheck.Add("Type", "NVARCHAR(255)"); |
355 |
dicColCheck.Add("SubType", "NVARCHAR(255)"); |
356 |
dicColCheck.Add("HeadItemTag", "NVARCHAR(255)"); |
357 |
dicColCheck.Add("TailItemTag", "NVARCHAR(255)"); |
358 |
dicColCheck.Add("HeadItemSPID", "NVARCHAR(255)"); |
359 |
dicColCheck.Add("TailItemSPID", "NVARCHAR(255)"); |
360 |
|
361 |
if (matched == null) |
362 |
{ |
363 |
var query = $"CREATE TABLE {PSN_TOPOLOGYSET} (OID NVARCHAR(255), Type NVARCHAR(255), SubType NVARCHAR(255), HeadItemTag NVARCHAR(255), TailItemTag NVARCHAR(255), HeadItemSPID NVARCHAR(255), TailItemSPID NVARCHAR(255))"; |
364 |
using (var cmd = connection.GetSqlStringCommand(query)) |
365 |
{ |
366 |
cmd.ExecuteNonQuery(); |
367 |
} |
368 |
} |
369 |
else |
370 |
{ |
371 |
AddColumn(PSN_TOPOLOGYSET, dicColCheck); |
372 |
} |
373 |
|
374 |
matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING); |
375 |
dicColCheck.Clear(); |
376 |
dicColCheck.Add("[INDEX]", "INTEGER"); |
377 |
dicColCheck.Add("[NAME]", "TEXT"); |
378 |
dicColCheck.Add("[KEYWORD]", "TEXT"); |
379 |
if (matched == null) |
380 |
{ |
381 |
var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)"; |
382 |
using (var cmd = connection.GetSqlStringCommand(query)) |
383 |
{ |
384 |
cmd.ExecuteNonQuery(); |
385 |
} |
386 |
} |
387 |
else |
388 |
{ |
389 |
AddColumn(PSN_TRANSFORMKEYWORD_SETTING, dicColCheck); |
390 |
} |
391 |
|
392 |
matched = names.FirstOrDefault(param => param == PSN_PIPELINE); |
393 |
dicColCheck.Clear(); |
394 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
395 |
dicColCheck.Add("PipeSystem_OID", "NVARCHAR(255)"); |
396 |
dicColCheck.Add("FLUID", "NVARCHAR(255)"); |
397 |
dicColCheck.Add("PMC", "NVARCHAR(255)"); |
398 |
dicColCheck.Add("SEQNUMBER", "NVARCHAR(255)"); |
399 |
dicColCheck.Add("INSULATION", "NVARCHAR(255)"); |
400 |
dicColCheck.Add("FROM_DATA", "NVARCHAR(255)"); |
401 |
dicColCheck.Add("TO_DATA", "NVARCHAR(255)"); |
402 |
dicColCheck.Add("Unit", "NVARCHAR(100)"); |
403 |
if (matched == null) |
404 |
{ |
405 |
var query = $"CREATE TABLE {PSN_PIPELINE} (OID NVARCHAR(255), PipeSystem_OID NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), SEQNUMBER NVARCHAR(255), INSULATION NVARCHAR(255), " + |
406 |
$"FROM_DATA NVARCHAR(255), TO_DATA NVARCHAR(255), Unit NVARCHAR(100))"; |
407 |
using (var cmd = connection.GetSqlStringCommand(query)) |
408 |
{ |
409 |
cmd.ExecuteNonQuery(); |
410 |
} |
411 |
} |
412 |
else |
413 |
{ |
414 |
AddColumn(PSN_PIPELINE, dicColCheck); |
415 |
} |
416 |
|
417 |
matched = names.FirstOrDefault(param => param == PSN_INSULATIONPURPOSE); |
418 |
dicColCheck.Clear(); |
419 |
dicColCheck.Add("UID", "NVARCHAR(50)"); |
420 |
dicColCheck.Add("Code", "NVARCHAR(255)"); |
421 |
dicColCheck.Add("Description", "NVARCHAR(255)"); |
422 |
dicColCheck.Add("Remarks", "NVARCHAR(255)"); |
423 |
if (matched == null) |
424 |
{ |
425 |
var query = $"CREATE TABLE {PSN_INSULATIONPURPOSE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Remarks NVARCHAR(255))"; |
426 |
using (var cmd = connection.GetSqlStringCommand(query)) |
427 |
{ |
428 |
cmd.ExecuteNonQuery(); |
429 |
} |
430 |
} |
431 |
else |
432 |
{ |
433 |
AddColumn(PSN_INSULATIONPURPOSE, dicColCheck); |
434 |
} |
435 |
|
436 |
matched = names.FirstOrDefault(param => param == PSN_VALVEGROUP_SETTING); |
437 |
dicColCheck.Clear(); |
438 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
439 |
dicColCheck.Add("GroupType", "NVARCHAR(255)"); |
440 |
dicColCheck.Add("TagIdentifier", "NVARCHAR(50)"); |
441 |
dicColCheck.Add("AttributeName", "NVARCHAR(255)"); |
442 |
dicColCheck.Add("SppidSymbolName", "NVARCHAR(255)"); |
443 |
if (matched == null) |
444 |
{ |
445 |
var query = $"CREATE TABLE {PSN_VALVEGROUP_SETTING} (OID NVARCHAR(255), GroupType NVARCHAR(255), TagIdentifier NVARCHAR(50), AttributeName NVARCHAR(255), SppidSymbolName NVARCHAR(255))"; |
446 |
using (var cmd = connection.GetSqlStringCommand(query)) |
447 |
{ |
448 |
cmd.ExecuteNonQuery(); |
449 |
} |
450 |
} |
451 |
else |
452 |
{ |
453 |
AddColumn(PSN_VALVEGROUP_SETTING, dicColCheck); |
454 |
} |
455 |
|
456 |
matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEM); |
457 |
dicColCheck.Clear(); |
458 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
459 |
dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)"); |
460 |
dicColCheck.Add("FLUID", "NVARCHAR(255)"); |
461 |
dicColCheck.Add("PMC", "NVARCHAR(255)"); |
462 |
dicColCheck.Add("PipeLineQty", "NVARCHAR(255)"); |
463 |
dicColCheck.Add("GroundLevel", "NVARCHAR(20)"); |
464 |
if (matched == null) |
465 |
{ |
466 |
var query = $"CREATE TABLE {PSN_PIPESYSTEM} (OID NVARCHAR(255), DESCRIPTION NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), PipeLineQty NVARCHAR(255), GroundLevel NVARCHAR(20))"; |
467 |
using (var cmd = connection.GetSqlStringCommand(query)) |
468 |
{ |
469 |
cmd.ExecuteNonQuery(); |
470 |
} |
471 |
} |
472 |
else |
473 |
{ |
474 |
AddColumn(PSN_PIPESYSTEM, dicColCheck); |
475 |
} |
476 |
|
477 |
matched = names.FirstOrDefault(param => param == PSN_NOPOCKETSETTING); |
478 |
dicColCheck.Clear(); |
479 |
dicColCheck.Add("[INDEX]", "INTEGER"); |
480 |
dicColCheck.Add("[TYPE]", "TEXT"); |
481 |
dicColCheck.Add("[NAME]", "TEXT"); |
482 |
if (matched == null) |
483 |
{ |
484 |
var query = $"CREATE TABLE {PSN_NOPOCKETSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)"; |
485 |
using (var cmd = connection.GetSqlStringCommand(query)) |
486 |
{ |
487 |
cmd.ExecuteNonQuery(); |
488 |
} |
489 |
} |
490 |
else |
491 |
{ |
492 |
AddColumn(PSN_NOPOCKETSETTING, dicColCheck); |
493 |
} |
494 |
|
495 |
|
496 |
void AddColumn(string TableName, Dictionary<string, string> dicCol) |
497 |
{ |
498 |
var colnames = connection.GetColumnNames(TableName); |
499 |
bool check = false; |
500 |
if (colnames != null) |
501 |
{ |
502 |
foreach (KeyValuePair<string, string> col in dicCol) |
503 |
{ |
504 |
check = false; |
505 |
foreach (string c in colnames) |
506 |
{ |
507 |
if (col.Key.Contains(c)) |
508 |
{ |
509 |
check = true; |
510 |
break; |
511 |
} |
512 |
} |
513 |
|
514 |
if (!check) //없으면 추가 |
515 |
{ |
516 |
string i = string.Empty; |
517 |
if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL")) |
518 |
i = "DEFAULT 0"; |
519 |
|
520 |
var query = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";"; |
521 |
using (var cmd = connection.GetSqlStringCommand(query)) |
522 |
{ |
523 |
cmd.ExecuteNonQuery(); |
524 |
} |
525 |
} |
526 |
} |
527 |
} |
528 |
} |
529 |
|
530 |
result = true; |
531 |
} |
532 |
catch (Exception ex) |
533 |
{ |
534 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
535 |
} |
536 |
} |
537 |
|
538 |
return result; |
539 |
} |
540 |
|
541 |
// ID2 DB 데이터 |
542 |
/// <summary> |
543 |
/// ID2 데이타베이스에서 OPC 데이터를 조회 |
544 |
/// </summary> |
545 |
/// <returns></returns> |
546 |
public static DataTable SelectOPCRelations() |
547 |
{ |
548 |
DataTable dt = null; |
549 |
ID2Info id2Info = ID2Info.GetInstance(); |
550 |
|
551 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
552 |
{ |
553 |
try |
554 |
{ |
555 |
var query = "SELECT * FROM OPCRelations;"; |
556 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
557 |
{ |
558 |
dt = ds.Tables[0].Copy(); |
559 |
} |
560 |
} |
561 |
catch (Exception ex) |
562 |
{ |
563 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
564 |
} |
565 |
} |
566 |
|
567 |
return dt; |
568 |
} |
569 |
|
570 |
/// <summary> |
571 |
/// ID2 데이타베이스에서 도면 데이터를 조회 |
572 |
/// </summary> |
573 |
/// <returns></returns> |
574 |
public static DataTable SelectDrawings() |
575 |
{ |
576 |
DataTable dt = null; |
577 |
ID2Info id2Info = ID2Info.GetInstance(); |
578 |
|
579 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
580 |
{ |
581 |
try |
582 |
{ |
583 |
var query = "SELECT DISTINCT NAME FROM [Drawings]"; |
584 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
585 |
{ |
586 |
dt = ds.Tables[0].Copy(); |
587 |
} |
588 |
} |
589 |
catch (Exception ex) |
590 |
{ |
591 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
592 |
} |
593 |
} |
594 |
|
595 |
return dt; |
596 |
} |
597 |
|
598 |
public static DataTable AllDrawings() |
599 |
{ |
600 |
DataTable dt = null; |
601 |
ID2Info id2Info = ID2Info.GetInstance(); |
602 |
|
603 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
604 |
{ |
605 |
try |
606 |
{ |
607 |
var query = "SELECT * FROM [Drawings]"; |
608 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
609 |
{ |
610 |
dt = ds.Tables[0].Copy(); |
611 |
} |
612 |
} |
613 |
catch (Exception ex) |
614 |
{ |
615 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
616 |
} |
617 |
} |
618 |
|
619 |
return dt; |
620 |
} |
621 |
|
622 |
public static DataTable SelectLineProperties() |
623 |
{ |
624 |
DataTable dt = null; |
625 |
ID2Info id2Info = ID2Info.GetInstance(); |
626 |
|
627 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
628 |
{ |
629 |
try |
630 |
{ |
631 |
var query = "SELECT * FROM LineProperties"; |
632 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
633 |
{ |
634 |
dt = ds.Tables[0].Copy(); |
635 |
} |
636 |
} |
637 |
catch (Exception ex) |
638 |
{ |
639 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
640 |
} |
641 |
} |
642 |
|
643 |
return dt; |
644 |
} |
645 |
|
646 |
public static DataTable SelectFluidCode() |
647 |
{ |
648 |
DataTable dt = null; |
649 |
ID2Info id2Info = ID2Info.GetInstance(); |
650 |
|
651 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
652 |
{ |
653 |
try |
654 |
{ |
655 |
var query = "SELECT * FROM FluidCode"; |
656 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
657 |
{ |
658 |
dt = ds.Tables[0].Copy(); |
659 |
} |
660 |
} |
661 |
catch (Exception ex) |
662 |
{ |
663 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
664 |
} |
665 |
} |
666 |
|
667 |
return dt; |
668 |
} |
669 |
|
670 |
public static DataTable SelectPipingMaterialsClass() |
671 |
{ |
672 |
DataTable dt = null; |
673 |
ID2Info id2Info = ID2Info.GetInstance(); |
674 |
|
675 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
676 |
{ |
677 |
try |
678 |
{ |
679 |
var query = "SELECT * FROM PipingMaterialsClass"; |
680 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
681 |
{ |
682 |
dt = ds.Tables[0].Copy(); |
683 |
} |
684 |
} |
685 |
catch (Exception ex) |
686 |
{ |
687 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
688 |
} |
689 |
} |
690 |
|
691 |
return dt; |
692 |
} |
693 |
|
694 |
public static DataTable SelectPSNPIPINGMATLCLASS() |
695 |
{ |
696 |
DataTable dt = null; |
697 |
ID2Info id2Info = ID2Info.GetInstance(); |
698 |
|
699 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
700 |
{ |
701 |
try |
702 |
{ |
703 |
var query = $"SELECT * FROM {PSN_PIPINGMATLCLASS}"; |
704 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
705 |
{ |
706 |
dt = ds.Tables[0].Copy(); |
707 |
} |
708 |
} |
709 |
catch (Exception ex) |
710 |
{ |
711 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
712 |
} |
713 |
} |
714 |
|
715 |
return dt; |
716 |
} |
717 |
|
718 |
public static DataTable SelectInsulationPurpose() |
719 |
{ |
720 |
DataTable dt = null; |
721 |
ID2Info id2Info = ID2Info.GetInstance(); |
722 |
|
723 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
724 |
{ |
725 |
try |
726 |
{ |
727 |
var query = "SELECT * FROM InsulationPurpose"; |
728 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
729 |
{ |
730 |
dt = ds.Tables[0].Copy(); |
731 |
} |
732 |
} |
733 |
catch (Exception ex) |
734 |
{ |
735 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
736 |
} |
737 |
} |
738 |
|
739 |
return dt; |
740 |
} |
741 |
|
742 |
public static DataTable SelectPSNINSULATIONPURPOSE() |
743 |
{ |
744 |
DataTable dt = null; |
745 |
ID2Info id2Info = ID2Info.GetInstance(); |
746 |
|
747 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
748 |
{ |
749 |
try |
750 |
{ |
751 |
var query = $"SELECT * FROM {PSN_INSULATIONPURPOSE}"; |
752 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
753 |
{ |
754 |
dt = ds.Tables[0].Copy(); |
755 |
} |
756 |
} |
757 |
catch (Exception ex) |
758 |
{ |
759 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
760 |
} |
761 |
} |
762 |
|
763 |
return dt; |
764 |
} |
765 |
|
766 |
public static DataTable SelectNominalDiameter() |
767 |
{ |
768 |
DataTable dt = null; |
769 |
ID2Info id2Info = ID2Info.GetInstance(); |
770 |
|
771 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
772 |
{ |
773 |
try |
774 |
{ |
775 |
var query = "SELECT * FROM NominalDiameter ORDER BY Metric DESC"; |
776 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
777 |
{ |
778 |
dt = ds.Tables[0].Copy(); |
779 |
} |
780 |
} |
781 |
catch (Exception ex) |
782 |
{ |
783 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
784 |
} |
785 |
} |
786 |
|
787 |
///TODO: need to check below code |
788 |
dt.Rows.RemoveAt(0); |
789 |
dt.Rows.RemoveAt(0); |
790 |
dt.Rows.RemoveAt(0); |
791 |
dt.Rows.RemoveAt(0); |
792 |
|
793 |
return dt; |
794 |
} |
795 |
|
796 |
public static DataTable SelectAllSymbolAttribute() |
797 |
{ |
798 |
DataTable dt = null; |
799 |
ID2Info id2Info = ID2Info.GetInstance(); |
800 |
|
801 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
802 |
{ |
803 |
try |
804 |
{ |
805 |
var query = "SELECT B.Name AS SymbolName, Attribute AS SymbolAttribute, A.SymbolType_UID ,Attribute ,DisplayAttribute ,AttributeType, Expression FROM SymbolAttribute A INNER JOIN Symbol B ON A.SymbolType_UID = B.SymbolType_UID; "; |
806 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
807 |
{ |
808 |
dt = ds.Tables[0].Copy(); |
809 |
} |
810 |
} |
811 |
catch (Exception ex) |
812 |
{ |
813 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
814 |
} |
815 |
} |
816 |
|
817 |
return dt; |
818 |
} |
819 |
|
820 |
public static DataTable SelectSymbolAttribute() |
821 |
{ |
822 |
DataTable dt = null; |
823 |
ID2Info id2Info = ID2Info.GetInstance(); |
824 |
|
825 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
826 |
{ |
827 |
try |
828 |
{ |
829 |
// var query = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;"; |
830 |
var query = "SELECT DISTINCT Attribute FROM SymbolAttribute;"; |
831 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
832 |
{ |
833 |
dt = ds.Tables[0].Copy(); |
834 |
} |
835 |
} |
836 |
catch (Exception ex) |
837 |
{ |
838 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
839 |
} |
840 |
} |
841 |
|
842 |
return dt; |
843 |
} |
844 |
|
845 |
public static DataTable SelectSymbolName() |
846 |
{ |
847 |
DataTable dt = null; |
848 |
ID2Info id2Info = ID2Info.GetInstance(); |
849 |
|
850 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
851 |
{ |
852 |
try |
853 |
{ |
854 |
var query = "SELECT * FROM SymbolName;"; |
855 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
856 |
{ |
857 |
dt = ds.Tables[0].Copy(); |
858 |
} |
859 |
} |
860 |
catch (Exception ex) |
861 |
{ |
862 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
863 |
} |
864 |
} |
865 |
|
866 |
return dt; |
867 |
} |
868 |
|
869 |
public static double[] GetDrawingSize() |
870 |
{ |
871 |
double[] result = null; |
872 |
|
873 |
ID2Info id2Info = ID2Info.GetInstance(); |
874 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
875 |
{ |
876 |
try |
877 |
{ |
878 |
var query = "SELECT value FROM Configuration WHERE Section = 'Area' AND [Key] = 'Drawing';"; |
879 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
880 |
{ |
881 |
if (ds.Tables[0].Rows.Count == 1) |
882 |
{ |
883 |
string value = ds.Tables[0].Rows[0][0].ToString(); |
884 |
string[] split = value.Split(new char[] { ',' }); |
885 |
result = new double[] { |
886 |
Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", string.Empty)), |
887 |
Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", string.Empty)), |
888 |
Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", string.Empty)), |
889 |
Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", string.Empty)) |
890 |
}; |
891 |
result = new double[] { |
892 |
Math.Min(result[0], result[2]), |
893 |
Math.Min(result[1], result[3]), |
894 |
Math.Max(result[0], result[2]), |
895 |
Math.Max(result[1], result[3]) |
896 |
}; |
897 |
} |
898 |
} |
899 |
} |
900 |
catch (Exception ex) |
901 |
{ |
902 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
903 |
} |
904 |
} |
905 |
|
906 |
return result; |
907 |
} |
908 |
|
909 |
public static DataTable GetEquipmentType() |
910 |
{ |
911 |
DataTable dt = null; |
912 |
ID2Info id2Info = ID2Info.GetInstance(); |
913 |
|
914 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
915 |
{ |
916 |
try |
917 |
{ |
918 |
var query = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';"; |
919 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
920 |
{ |
921 |
dt = ds.Tables[0].Copy(); |
922 |
} |
923 |
} |
924 |
catch (Exception ex) |
925 |
{ |
926 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
927 |
} |
928 |
} |
929 |
|
930 |
return dt; |
931 |
} |
932 |
|
933 |
/// <summary> |
934 |
/// Zoom 을 위하여 저장 T_PSN_VIEW 데이터로 PSN 데이터지만 Msqql 과 Sqlite 둘다 저장되어 있음 |
935 |
/// => ID2 가 DB 타입에 따라서 바라보는 DB가 mssql이냐 sqlite냐로 지정되기 때문에 zoom 기능을 그대로 사용하려면 해당 데이터는 psn도 id2 dbtype에 맞춰서 저장 및 로드해야함 |
936 |
/// => 더 이상 사용하지 않음 |
937 |
/// </summary> |
938 |
/// <param name="values"></param> |
939 |
/// <returns></returns> |
940 |
public static bool SaveView(List<string> values) |
941 |
{ |
942 |
ID2Info id2Info = ID2Info.GetInstance(); |
943 |
|
944 |
bool result = true; |
945 |
|
946 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
947 |
{ |
948 |
try |
949 |
{ |
950 |
using (var txn = connection.BeginTransaction()) |
951 |
{ |
952 |
try |
953 |
{ |
954 |
var query = $"DELETE FROM {PSN_VIEW}"; |
955 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
956 |
|
957 |
foreach (string value in values) |
958 |
{ |
959 |
query = $"INSERT INTO {PSN_VIEW} (OID) VALUES (@OID)"; |
960 |
var cmd = connection.GetSqlStringCommand(query); |
961 |
AddWithValue(cmd, "@OID", value); |
962 |
connection.ExecuteNonQuery(cmd, txn); |
963 |
} |
964 |
txn.Commit(); |
965 |
} |
966 |
catch (Exception ex) |
967 |
{ |
968 |
txn.Rollback(); |
969 |
result = false; |
970 |
} |
971 |
} |
972 |
} |
973 |
catch (Exception ex) |
974 |
{ |
975 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
976 |
result = false; |
977 |
} |
978 |
} |
979 |
|
980 |
return result; |
981 |
} |
982 |
|
983 |
public static bool DeleteView() |
984 |
{ |
985 |
ID2Info id2Info = ID2Info.GetInstance(); |
986 |
|
987 |
bool result = true; |
988 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
989 |
{ |
990 |
try |
991 |
{ |
992 |
using (var txn = connection.BeginTransaction()) |
993 |
{ |
994 |
try |
995 |
{ |
996 |
var query = $"DELETE FROM {PSN_VIEW}"; |
997 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
998 |
txn.Commit(); |
999 |
} |
1000 |
catch (Exception ex) |
1001 |
{ |
1002 |
txn.Rollback(); |
1003 |
result = false; |
1004 |
} |
1005 |
} |
1006 |
} |
1007 |
catch (Exception ex) |
1008 |
{ |
1009 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
1010 |
result = false; |
1011 |
} |
1012 |
} |
1013 |
|
1014 |
return result; |
1015 |
} |
1016 |
|
1017 |
//PSN Sqlite |
1018 |
public static DataTable SelectHeaderSetting() |
1019 |
{ |
1020 |
DataTable dt = null; |
1021 |
ID2Info id2Info = ID2Info.GetInstance(); |
1022 |
|
1023 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1024 |
{ |
1025 |
try |
1026 |
{ |
1027 |
var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_HEADER_SETTING};"; |
1028 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1029 |
{ |
1030 |
dt = ds.Tables[0].Copy(); |
1031 |
} |
1032 |
} |
1033 |
catch (Exception ex) |
1034 |
{ |
1035 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1036 |
} |
1037 |
} |
1038 |
|
1039 |
return dt; |
1040 |
} |
1041 |
|
1042 |
public static DataTable SelectVentDrainSetting() |
1043 |
{ |
1044 |
DataTable dt = null; |
1045 |
ID2Info id2Info = ID2Info.GetInstance(); |
1046 |
|
1047 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1048 |
{ |
1049 |
try |
1050 |
{ |
1051 |
var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_VENTDRAIN_SETTING};"; |
1052 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1053 |
{ |
1054 |
dt = ds.Tables[0].Copy(); |
1055 |
} |
1056 |
} |
1057 |
catch (Exception ex) |
1058 |
{ |
1059 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1060 |
} |
1061 |
} |
1062 |
|
1063 |
return dt; |
1064 |
} |
1065 |
|
1066 |
public static DataTable SelectKeywordsSetting() |
1067 |
{ |
1068 |
DataTable dt = null; |
1069 |
ID2Info id2Info = ID2Info.GetInstance(); |
1070 |
|
1071 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1072 |
{ |
1073 |
try |
1074 |
{ |
1075 |
var query = $@"SELECT [KEYWORD], [INDEX], [NAME] FROM {PSN_TRANSFORMKEYWORD_SETTING};"; |
1076 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1077 |
{ |
1078 |
dt = ds.Tables[0].Copy(); |
1079 |
} |
1080 |
} |
1081 |
catch (Exception ex) |
1082 |
{ |
1083 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1084 |
} |
1085 |
} |
1086 |
|
1087 |
return dt; |
1088 |
} |
1089 |
|
1090 |
public static DataTable SelectValveGroupItemsSetting() |
1091 |
{ |
1092 |
DataTable dt = null; |
1093 |
ID2Info id2Info = ID2Info.GetInstance(); |
1094 |
|
1095 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1096 |
{ |
1097 |
try |
1098 |
{ |
1099 |
var query = $@"SELECT OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName FROM {PSN_VALVEGROUP_SETTING};"; |
1100 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1101 |
{ |
1102 |
dt = ds.Tables[0].Copy(); |
1103 |
} |
1104 |
} |
1105 |
catch (Exception ex) |
1106 |
{ |
1107 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1108 |
} |
1109 |
} |
1110 |
|
1111 |
return dt; |
1112 |
} |
1113 |
|
1114 |
public static DataTable SelectEquipmentNoPocketSetting() |
1115 |
{ |
1116 |
DataTable dt = null; |
1117 |
ID2Info id2Info = ID2Info.GetInstance(); |
1118 |
|
1119 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1120 |
{ |
1121 |
try |
1122 |
{ |
1123 |
var query = $@"SELECT [INDEX], [TYPE], [NAME] FROM {PSN_NOPOCKETSETTING};"; |
1124 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1125 |
{ |
1126 |
dt = ds.Tables[0].Copy(); |
1127 |
} |
1128 |
} |
1129 |
catch (Exception ex) |
1130 |
{ |
1131 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1132 |
} |
1133 |
} |
1134 |
|
1135 |
return dt; |
1136 |
} |
1137 |
|
1138 |
public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos) |
1139 |
{ |
1140 |
ID2Info id2Info = ID2Info.GetInstance(); |
1141 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1142 |
{ |
1143 |
try |
1144 |
{ |
1145 |
using (var txn = connection.BeginTransaction()) |
1146 |
{ |
1147 |
var query = $"DELETE FROM {PSN_HEADER_SETTING}"; |
1148 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1149 |
|
1150 |
foreach (HeaderInfo headerInfo in headerInfos) |
1151 |
{ |
1152 |
foreach (HeaderItem item in headerInfo.HeaderItems) |
1153 |
{ |
1154 |
query = $"INSERT INTO {PSN_HEADER_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)"; |
1155 |
var cmd = connection.GetSqlStringCommand(query); |
1156 |
AddWithValue(cmd, "@GROUP_ID", headerInfo.UID); |
1157 |
AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description); |
1158 |
AddWithValue(cmd, "@INDEX", item.Index); |
1159 |
AddWithValue(cmd, "@NAME", item.Name); |
1160 |
connection.ExecuteNonQuery(cmd, txn); |
1161 |
} |
1162 |
} |
1163 |
txn.Commit(); |
1164 |
} |
1165 |
|
1166 |
} |
1167 |
catch (Exception ex) |
1168 |
{ |
1169 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1170 |
return false; |
1171 |
} |
1172 |
} |
1173 |
return true; |
1174 |
} |
1175 |
|
1176 |
public static bool SaveVentDrainSetting(List<VentDrainInfo> ventDrainInfos) |
1177 |
{ |
1178 |
ID2Info id2Info = ID2Info.GetInstance(); |
1179 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1180 |
{ |
1181 |
using (var txn = connection.BeginTransaction()) |
1182 |
{ |
1183 |
try |
1184 |
{ |
1185 |
var query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}"; |
1186 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1187 |
|
1188 |
foreach (VentDrainInfo ventDrainInfo in ventDrainInfos) |
1189 |
{ |
1190 |
foreach (VentDrainItem item in ventDrainInfo.VentDrainItems) |
1191 |
{ |
1192 |
query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)"; |
1193 |
var cmd = connection.GetSqlStringCommand(query); |
1194 |
AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID); |
1195 |
AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description); |
1196 |
AddWithValue(cmd, "@INDEX", item.Index); |
1197 |
AddWithValue(cmd, "@NAME", item.Name); |
1198 |
connection.ExecuteNonQuery(cmd, txn); |
1199 |
} |
1200 |
} |
1201 |
|
1202 |
txn.Commit(); |
1203 |
} |
1204 |
catch (Exception ex) |
1205 |
{ |
1206 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1207 |
return false; |
1208 |
} |
1209 |
} |
1210 |
} |
1211 |
|
1212 |
return true; |
1213 |
} |
1214 |
|
1215 |
public static bool SaveValveGroupItemsSetting(List<ValveGroupItem> valveGroupItems) |
1216 |
{ |
1217 |
ID2Info id2Info = ID2Info.GetInstance(); |
1218 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1219 |
{ |
1220 |
using (var txn = connection.BeginTransaction()) |
1221 |
{ |
1222 |
try |
1223 |
{ |
1224 |
var query = $"DELETE FROM {PSN_VALVEGROUP_SETTING}"; |
1225 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1226 |
|
1227 |
foreach (ValveGroupItem item in valveGroupItems) |
1228 |
{ |
1229 |
query = $"INSERT INTO {PSN_VALVEGROUP_SETTING} (OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName) " + |
1230 |
$"VALUES (@OID, @GroupType, @TagIdentifier, @AttributeName, @SppidSymbolName)"; |
1231 |
var cmd = connection.GetSqlStringCommand(query); |
1232 |
AddWithValue(cmd, "@OID", item.OID); |
1233 |
AddWithValue(cmd, "@GroupType", item.GroupType); |
1234 |
AddWithValue(cmd, "@TagIdentifier", item.TagIdentifier); |
1235 |
AddWithValue(cmd, "@AttributeName", item.AttributeName); |
1236 |
AddWithValue(cmd, "@SppidSymbolName", item.SppidSymbolName); |
1237 |
connection.ExecuteNonQuery(cmd, txn); |
1238 |
} |
1239 |
|
1240 |
txn.Commit(); |
1241 |
} |
1242 |
catch (Exception ex) |
1243 |
{ |
1244 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1245 |
return false; |
1246 |
} |
1247 |
} |
1248 |
} |
1249 |
|
1250 |
return true; |
1251 |
} |
1252 |
|
1253 |
public static bool SaveKeywordsSetting(List<KeywordItem> keywordItems) |
1254 |
{ |
1255 |
ID2Info id2Info = ID2Info.GetInstance(); |
1256 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1257 |
{ |
1258 |
using (var txn = connection.BeginTransaction()) |
1259 |
{ |
1260 |
try |
1261 |
{ |
1262 |
var query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}"; |
1263 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1264 |
|
1265 |
foreach (KeywordItem item in keywordItems) |
1266 |
{ |
1267 |
query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX], NAME, KEYWORD) VALUES (@INDEX, @NAME, @KEYWORD)"; |
1268 |
var cmd = connection.GetSqlStringCommand(query); |
1269 |
AddWithValue(cmd, "@INDEX", item.Index); |
1270 |
AddWithValue(cmd, "@NAME", item.Name); |
1271 |
AddWithValue(cmd, "@KEYWORD", item.Keyword); |
1272 |
connection.ExecuteNonQuery(cmd, txn); |
1273 |
} |
1274 |
|
1275 |
txn.Commit(); |
1276 |
} |
1277 |
catch (Exception ex) |
1278 |
{ |
1279 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1280 |
return false; |
1281 |
} |
1282 |
} |
1283 |
} |
1284 |
|
1285 |
return true; |
1286 |
} |
1287 |
|
1288 |
public static bool SaveEquipmentNopocketSetting(List<EquipmentNoPocketItem> keywordItems) |
1289 |
{ |
1290 |
ID2Info id2Info = ID2Info.GetInstance(); |
1291 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1292 |
{ |
1293 |
using (var txn = connection.BeginTransaction()) |
1294 |
{ |
1295 |
try |
1296 |
{ |
1297 |
var query = $"DELETE FROM {PSN_NOPOCKETSETTING}"; |
1298 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1299 |
|
1300 |
foreach (EquipmentNoPocketItem item in keywordItems) |
1301 |
{ |
1302 |
query = $"INSERT INTO {PSN_NOPOCKETSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)"; |
1303 |
var cmd = connection.GetSqlStringCommand(query); |
1304 |
AddWithValue(cmd, "@INDEX", item.Index); |
1305 |
AddWithValue(cmd, "@TYPE", item.Type); |
1306 |
AddWithValue(cmd, "@NAME", item.Name); |
1307 |
connection.ExecuteNonQuery(cmd, txn); |
1308 |
} |
1309 |
|
1310 |
txn.Commit(); |
1311 |
} |
1312 |
catch (Exception ex) |
1313 |
{ |
1314 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1315 |
return false; |
1316 |
} |
1317 |
} |
1318 |
} |
1319 |
|
1320 |
return true; |
1321 |
} |
1322 |
|
1323 |
public static bool SaveTopologyRule(DataTable dt) |
1324 |
{ |
1325 |
ID2Info id2Info = ID2Info.GetInstance(); |
1326 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1327 |
{ |
1328 |
using (var txn = connection.BeginTransaction()) |
1329 |
{ |
1330 |
try |
1331 |
{ |
1332 |
var query = $"DELETE FROM {PSN_TOPOLOGY_RULE}"; |
1333 |
var cmd = connection.GetSqlStringCommand(query); |
1334 |
//connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1335 |
connection.ExecuteNonQuery(cmd, txn); |
1336 |
|
1337 |
foreach (DataRow row in dt.Rows) |
1338 |
{ |
1339 |
query = $"INSERT INTO {PSN_TOPOLOGY_RULE} (UID) VALUES (@UID)"; |
1340 |
cmd = connection.GetSqlStringCommand(query); |
1341 |
AddWithValue(cmd, "@UID", row["NAME"].ToString()); |
1342 |
connection.ExecuteNonQuery(cmd, txn); |
1343 |
} |
1344 |
|
1345 |
txn.Commit(); |
1346 |
} |
1347 |
catch (Exception ex) |
1348 |
{ |
1349 |
txn.Rollback(); |
1350 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1351 |
return false; |
1352 |
} |
1353 |
} |
1354 |
} |
1355 |
|
1356 |
return true; |
1357 |
} |
1358 |
|
1359 |
public static DataTable SelectTopologyRule() |
1360 |
{ |
1361 |
DataTable dt = null; |
1362 |
|
1363 |
ID2Info id2Info = ID2Info.GetInstance(); |
1364 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1365 |
{ |
1366 |
try |
1367 |
{ |
1368 |
var query = $"SELECT * FROM {PSN_TOPOLOGY_RULE}"; |
1369 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1370 |
{ |
1371 |
dt = ds.Tables[0].Copy(); |
1372 |
} |
1373 |
} |
1374 |
catch (Exception ex) |
1375 |
{ |
1376 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1377 |
} |
1378 |
} |
1379 |
|
1380 |
return dt; |
1381 |
} |
1382 |
|
1383 |
private static void AddWithValue(DbCommand cmd, string PropName, object Value) |
1384 |
{ |
1385 |
var param = cmd.CreateParameter(); |
1386 |
param.ParameterName = PropName; |
1387 |
param.Value = Value; |
1388 |
cmd.Parameters.Add(param); |
1389 |
} |
1390 |
|
1391 |
public static DataTable SelectRevisionTable() |
1392 |
{ |
1393 |
DataTable dt = null; |
1394 |
ID2Info id2Info = ID2Info.GetInstance(); |
1395 |
|
1396 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1397 |
{ |
1398 |
try |
1399 |
{ |
1400 |
var query = $"SELECT T.name AS table_name, C.name AS column_name FROM ARS_COMMON.sys.tables AS T INNER JOIN ARS_COMMON.sys.columns AS C ON T.object_id = C.object_id WHERE T.name = 'PSNREVISION'"; |
1401 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1402 |
{ |
1403 |
dt = ds.Tables[0].Copy(); |
1404 |
} |
1405 |
} |
1406 |
catch (Exception ex) |
1407 |
{ |
1408 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1409 |
} |
1410 |
} |
1411 |
|
1412 |
return dt; |
1413 |
} |
1414 |
|
1415 |
public static DataTable SelectRevision() |
1416 |
{ |
1417 |
DataTable dt = null; |
1418 |
ID2Info id2Info = ID2Info.GetInstance(); |
1419 |
|
1420 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1421 |
{ |
1422 |
try |
1423 |
{ |
1424 |
var query = $"SELECT * FROM ARS_COMMON.dbo.PSNREVISION"; |
1425 |
|
1426 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
1427 |
{ |
1428 |
dt = ds.Tables[0].Copy(); |
1429 |
} |
1430 |
} |
1431 |
catch (Exception ex) |
1432 |
{ |
1433 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1434 |
} |
1435 |
} |
1436 |
|
1437 |
return dt; |
1438 |
} |
1439 |
|
1440 |
public static bool ConnCreateRevisionTable(Dictionary<string, string> dicColCheck, List<string> names) |
1441 |
{ |
1442 |
bool result = false; |
1443 |
ID2Info id2Info = ID2Info.GetInstance(); |
1444 |
|
1445 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1446 |
{ |
1447 |
try |
1448 |
{ |
1449 |
if (names.Count == 0) |
1450 |
{ |
1451 |
|
1452 |
var query = $"CREATE TABLE ARS_COMMON.dbo.PSNRevision ([OID] [uniqueidentifier] ,[Project_OID] [uniqueidentifier] ," + |
1453 |
$"[ProjectCode] nvarchar(255), [RevNumber] int ,[UserName] nvarchar(255) ,[TimeData] nvarchar(255) ," + |
1454 |
$"[PSNDatabasePath] nvarchar(255) , [PsnByPBSFilter] varchar(20) ,[PsnByNPDFilter] varchar(20) ,[PidDrawings] int , " + |
1455 |
$"[PipeSystems] int ,[PipeLines] int ,[Topologies] int ,[PipeSystemNetworks] int ,[InValidPSNs] int ,[E2E] int ," + |
1456 |
$"[E2B] int ,[B2E] int ,[HDE] int ,[HD2] int ,[HDB] int ,[B2B] int, [LastModificationdate] nvarchar(255))"; |
1457 |
using (var cmd = connection.GetSqlStringCommand(query)) |
1458 |
{ |
1459 |
cmd.ExecuteNonQuery(); |
1460 |
} |
1461 |
} |
1462 |
else |
1463 |
{ |
1464 |
AddColumn(PSN_REVISION, dicColCheck, names); |
1465 |
} |
1466 |
|
1467 |
void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames) |
1468 |
{ |
1469 |
bool check = false; |
1470 |
if (colnames != null) |
1471 |
{ |
1472 |
foreach (KeyValuePair<string, string> col in dicCol) |
1473 |
{ |
1474 |
check = false; |
1475 |
foreach (string c in colnames) |
1476 |
{ |
1477 |
if (col.Key.Contains(c)) |
1478 |
{ |
1479 |
check = true; |
1480 |
break; |
1481 |
} |
1482 |
} |
1483 |
|
1484 |
if (!check) //없으면 추가 |
1485 |
{ |
1486 |
string i = string.Empty; |
1487 |
if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL")) |
1488 |
i = "DEFAULT 0"; |
1489 |
|
1490 |
var queryalter = $"ALTER TABLE ARS_COMMON.dbo.PSNRevision ADD [" + col.Key + "] " + col.Value + " " + i + ";"; |
1491 |
using (var cmd = connection.GetSqlStringCommand(queryalter)) |
1492 |
{ |
1493 |
cmd.ExecuteNonQuery(); |
1494 |
} |
1495 |
} |
1496 |
} |
1497 |
} |
1498 |
} |
1499 |
|
1500 |
result = true; |
1501 |
} |
1502 |
catch (Exception ex) |
1503 |
{ |
1504 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1505 |
} |
1506 |
} |
1507 |
|
1508 |
return result; |
1509 |
} |
1510 |
|
1511 |
public static bool UpdateRevision(string TimeData, string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter, |
1512 |
int PidDrawings, int PipeSystems, int PipeLines, int Topologies, int PipeSystemNetworks, int InValidPSNs, int E2E, int E2B, int B2E, int HDE, int HD2, int HDB, int B2B) |
1513 |
{ |
1514 |
ID2Info id2Info = ID2Info.GetInstance(); |
1515 |
bool result = true; |
1516 |
|
1517 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1518 |
{ |
1519 |
try |
1520 |
{ |
1521 |
using (var txn = connection.BeginTransaction()) |
1522 |
{ |
1523 |
try |
1524 |
{ |
1525 |
string where = string.Format("DELETE FROM ARS_COMMON.dbo.PSNRevision WHERE ProjectCode = '{0}' AND PSNDatabasePath = '{1}' AND RevNumber = {2}", ProjectCode, PSNDatabasePath, RevNumber); |
1526 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(where), txn); |
1527 |
var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " + |
1528 |
$"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " + |
1529 |
$"HD2, HDB, B2B, LastModificationdate) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" + |
1530 |
$", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " + |
1531 |
$"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate)"; |
1532 |
var cmd = connection.GetSqlStringCommand(query); |
1533 |
|
1534 |
AddWithValue(cmd, "@ProjectCode", ProjectCode); |
1535 |
AddWithValue(cmd, "@RevNumber", RevNumber); |
1536 |
AddWithValue(cmd, "@UserName", UserName); |
1537 |
AddWithValue(cmd, "@TimeData", TimeData); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") |
1538 |
|
1539 |
AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath); |
1540 |
|
1541 |
AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter); |
1542 |
AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter); |
1543 |
AddWithValue(cmd, "@PidDrawings", PidDrawings); |
1544 |
AddWithValue(cmd, "@PipeSystems", PipeSystems); |
1545 |
AddWithValue(cmd, "@PipeLines", PipeLines); |
1546 |
|
1547 |
AddWithValue(cmd, "@Topologies", Topologies); |
1548 |
AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks); |
1549 |
AddWithValue(cmd, "@InValidPSNs", InValidPSNs); |
1550 |
AddWithValue(cmd, "@E2E", E2E); |
1551 |
AddWithValue(cmd, "@E2B", E2B); |
1552 |
AddWithValue(cmd, "@B2E", B2E); |
1553 |
AddWithValue(cmd, "@HDE", HDE); |
1554 |
AddWithValue(cmd, "@HD2", HD2); |
1555 |
AddWithValue(cmd, "@HDB", HDB); |
1556 |
AddWithValue(cmd, "@B2B", B2B); |
1557 |
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US"); |
1558 |
DateTime oDateTime = DateTime.Now; |
1559 |
AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci)); |
1560 |
connection.ExecuteNonQuery(cmd, txn); |
1561 |
|
1562 |
txn.Commit(); |
1563 |
} |
1564 |
catch (Exception ex) |
1565 |
{ |
1566 |
txn.Rollback(); |
1567 |
result = false; |
1568 |
} |
1569 |
} |
1570 |
} |
1571 |
catch (Exception ex) |
1572 |
{ |
1573 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
1574 |
result = false; |
1575 |
} |
1576 |
} |
1577 |
|
1578 |
return result; |
1579 |
} |
1580 |
|
1581 |
|
1582 |
public static bool SaveRevision(string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter, |
1583 |
int PidDrawings, int PipeSystems, int PipeLines, int Topologies, int PipeSystemNetworks, int InValidPSNs, int E2E, int E2B, int B2E, int HDE, int HD2, int HDB, int B2B) |
1584 |
{ |
1585 |
ID2Info id2Info = ID2Info.GetInstance(); |
1586 |
|
1587 |
bool result = true; |
1588 |
|
1589 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1590 |
{ |
1591 |
try |
1592 |
{ |
1593 |
using (var txn = connection.BeginTransaction()) |
1594 |
{ |
1595 |
try |
1596 |
{ |
1597 |
|
1598 |
var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " + |
1599 |
$"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " + |
1600 |
$"HD2, HDB, B2B, LastModificationdate) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" + |
1601 |
$", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " + |
1602 |
$"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate)"; |
1603 |
var cmd = connection.GetSqlStringCommand(query); |
1604 |
AddWithValue(cmd, "@OID", Guid.NewGuid().ToString()); |
1605 |
AddWithValue(cmd, "@Project_OID", Guid.NewGuid().ToString()); |
1606 |
AddWithValue(cmd, "@ProjectCode", ProjectCode); |
1607 |
AddWithValue(cmd, "@RevNumber", RevNumber); |
1608 |
AddWithValue(cmd, "@UserName", UserName); |
1609 |
|
1610 |
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US"); |
1611 |
DateTime oDateTime = DateTime.Now; |
1612 |
|
1613 |
AddWithValue(cmd, "@TimeData", oDateTime.ToString(ci)); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") |
1614 |
|
1615 |
AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath); |
1616 |
|
1617 |
AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter); |
1618 |
AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter); |
1619 |
AddWithValue(cmd, "@PidDrawings", PidDrawings); |
1620 |
AddWithValue(cmd, "@PipeSystems", PipeSystems); |
1621 |
AddWithValue(cmd, "@PipeLines", PipeLines); |
1622 |
|
1623 |
AddWithValue(cmd, "@Topologies", Topologies); |
1624 |
AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks); |
1625 |
AddWithValue(cmd, "@InValidPSNs", InValidPSNs); |
1626 |
AddWithValue(cmd, "@E2E", E2E); |
1627 |
AddWithValue(cmd, "@E2B", E2B); |
1628 |
AddWithValue(cmd, "@B2E", B2E); |
1629 |
AddWithValue(cmd, "@HDE", HDE); |
1630 |
AddWithValue(cmd, "@HD2", HD2); |
1631 |
AddWithValue(cmd, "@HDB", HDB); |
1632 |
AddWithValue(cmd, "@B2B", B2B); |
1633 |
AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci)); |
1634 |
connection.ExecuteNonQuery(cmd, txn); |
1635 |
|
1636 |
txn.Commit(); |
1637 |
} |
1638 |
catch (Exception ex) |
1639 |
{ |
1640 |
txn.Rollback(); |
1641 |
result = false; |
1642 |
} |
1643 |
} |
1644 |
} |
1645 |
catch (Exception ex) |
1646 |
{ |
1647 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
1648 |
result = false; |
1649 |
} |
1650 |
} |
1651 |
|
1652 |
return result; |
1653 |
} |
1654 |
|
1655 |
public static bool SavePSNData(PSN item) |
1656 |
{ |
1657 |
ID2Info id2Info = ID2Info.GetInstance(); |
1658 |
|
1659 |
bool result = true; |
1660 |
|
1661 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1662 |
{ |
1663 |
try |
1664 |
{ |
1665 |
using (var txn = connection.BeginTransaction()) |
1666 |
{ |
1667 |
try |
1668 |
{ |
1669 |
// Path Items |
1670 |
var query = $"DELETE FROM {PSN_PATHITEMS}"; |
1671 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1672 |
for (int i = 0; i < item.PathItems.Rows.Count; i++) |
1673 |
{ |
1674 |
DataRow row = item.PathItems.Rows[i]; |
1675 |
query = $"INSERT INTO {PSN_PATHITEMS} " + |
1676 |
$"(OID, SequenceData_OID, TopologySet_OID, BranchTopologySet_OID, PipeLine_OID, ItemName, ItemTag, DESCRIPTION, CLASS, SUBCLASS, TYPE, " + |
1677 |
$"PIDNAME, Equipment_OID, NPD, GROUPTAG, PipeSystemNetwork_OID, PipeRun_OID, ViewPipeSystemNetwork_OID) VALUES " + |
1678 |
$"(@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @DESCRIPTION, @Class, @SubClass, @TYPE, @PIDNAME, " + |
1679 |
$"@Equipment_OID, @NPD, @GROUPTAG, @PipeSystemNetwork_OID,@PipeRun_OID, @ViewPipeSystemNetwork_OID)"; |
1680 |
var cmd = connection.GetSqlStringCommand(query); |
1681 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
1682 |
AddWithValue(cmd, "@SequenceData_OID", string.IsNullOrEmpty(row["SequenceData_OID"].ToString()) ? "" : row["SequenceData_OID"].ToString()); |
1683 |
AddWithValue(cmd, "@TopologySet_OID", string.IsNullOrEmpty(row["TopologySet_OID"].ToString()) ? "" : row["TopologySet_OID"].ToString()); |
1684 |
AddWithValue(cmd, "@BranchTopologySet_OID", string.IsNullOrEmpty(row["BranchTopologySet_OID"].ToString()) ? "" : row["BranchTopologySet_OID"].ToString()); |
1685 |
AddWithValue(cmd, "@PipeLine_OID", string.IsNullOrEmpty(row["PipeLine_OID"].ToString()) ? "" : row["PipeLine_OID"].ToString()); |
1686 |
AddWithValue(cmd, "@ITEMNAME", string.IsNullOrEmpty(row["ITEMNAME"].ToString()) ? "" : row["ITEMNAME"].ToString()); |
1687 |
AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString()); |
1688 |
AddWithValue(cmd, "@DESCRIPTION", string.IsNullOrEmpty(row["DESCRIPTION"].ToString()) ? "" : row["DESCRIPTION"].ToString()); |
1689 |
AddWithValue(cmd, "@Class", string.IsNullOrEmpty(row["Class"].ToString()) ? "" : row["Class"].ToString()); |
1690 |
AddWithValue(cmd, "@SubClass", string.IsNullOrEmpty(row["SubClass"].ToString()) ? "" : row["SubClass"].ToString()); |
1691 |
AddWithValue(cmd, "@TYPE", string.IsNullOrEmpty(row["TYPE"].ToString()) ? "" : row["TYPE"].ToString()); |
1692 |
AddWithValue(cmd, "@PIDNAME", string.IsNullOrEmpty(row["PIDNAME"].ToString()) ? "" : row["PIDNAME"].ToString()); |
1693 |
AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString()); |
1694 |
AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString()); |
1695 |
AddWithValue(cmd, "@GROUPTAG", string.IsNullOrEmpty(row["GROUPTAG"].ToString()) ? "" : row["GROUPTAG"].ToString()); |
1696 |
AddWithValue(cmd, "@PipeSystemNetwork_OID", string.IsNullOrEmpty(row["PipeSystemNetwork_OID"].ToString()) ? "" : row["PipeSystemNetwork_OID"].ToString()); |
1697 |
AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", string.IsNullOrEmpty(row["ViewPipeSystemNetwork_OID"].ToString()) ? "" : row["ViewPipeSystemNetwork_OID"].ToString()); |
1698 |
AddWithValue(cmd, "@PipeRun_OID", string.IsNullOrEmpty(row["PipeRun_OID"].ToString()) ? "" : row["PipeRun_OID"].ToString()); |
1699 |
connection.ExecuteNonQuery(cmd, txn); |
1700 |
} |
1701 |
|
1702 |
// Sequence |
1703 |
query = $"DELETE FROM {PSN_SEQUENCEDATA}"; |
1704 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1705 |
foreach (DataRow row in item.SequenceData.Rows) |
1706 |
{ |
1707 |
query = $"INSERT INTO {PSN_SEQUENCEDATA} (OID, SERIALNUMBER, PathItem_OID, TopologySet_OID_Key) VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)"; |
1708 |
var cmd = connection.GetSqlStringCommand(query); |
1709 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
1710 |
AddWithValue(cmd, "@SERIALNUMBER", string.IsNullOrEmpty(row["SERIALNUMBER"].ToString()) ? "" : row["SERIALNUMBER"].ToString()); |
1711 |
AddWithValue(cmd, "@PathItem_OID", string.IsNullOrEmpty(row["PathItem_OID"].ToString()) ? "" : row["PathItem_OID"].ToString()); |
1712 |
AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString()); |
1713 |
connection.ExecuteNonQuery(cmd, txn); |
1714 |
} |
1715 |
|
1716 |
// Nozzle |
1717 |
query = $"DELETE FROM {PSN_NOZZLE}"; |
1718 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1719 |
foreach (DataRow row in item.Nozzle.Rows) |
1720 |
{ |
1721 |
query = $"INSERT INTO {PSN_NOZZLE} (OID, ItemTag, Xcoords, Ycoords, Equipment_OID, Fluid, NPD, PMC, Rotation, FlowDirection) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @PMC, @ROTATION, @FlowDirection)"; |
1722 |
var cmd = connection.GetSqlStringCommand(query); |
1723 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
1724 |
AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString()); |
1725 |
|
1726 |
if (string.IsNullOrEmpty(row["XCOORDS"].ToString())) |
1727 |
AddWithValue(cmd, "@XCOORDS", DBNull.Value); |
1728 |
else |
1729 |
AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString()); |
1730 |
|
1731 |
if (string.IsNullOrEmpty(row["YCOORDS"].ToString())) |
1732 |
AddWithValue(cmd, "@YCOORDS", DBNull.Value); |
1733 |
else |
1734 |
AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString()); |
1735 |
|
1736 |
AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString()); |
1737 |
AddWithValue(cmd, "@FLUID", string.IsNullOrEmpty(row["FLUID"].ToString()) ? "" : row["FLUID"].ToString()); |
1738 |
AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString()); |
1739 |
AddWithValue(cmd, "@PMC", string.IsNullOrEmpty(row["PMC"].ToString()) ? "" : row["PMC"].ToString()); |
1740 |
|
1741 |
if (string.IsNullOrEmpty(row["ROTATION"].ToString())) |
1742 |
AddWithValue(cmd, "@ROTATION", DBNull.Value); |
1743 |
else |
1744 |
AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString()); |
1745 |
|
1746 |
AddWithValue(cmd, "@FlowDirection", string.IsNullOrEmpty(row["FlowDirection"].ToString()) ? "" : row["FlowDirection"].ToString()); |
1747 |
connection.ExecuteNonQuery(cmd, txn); |
1748 |
} |
1749 |
|
1750 |
//Equipment |
1751 |
query = $"DELETE FROM {PSN_EQUIPMENT}"; |
1752 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1753 |
foreach (DataRow row in item.Equipment.Rows) |
1754 |
{ |
1755 |
query = $"INSERT INTO {PSN_EQUIPMENT} (OID, ItemTag, Xcoords, Ycoords) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)"; |
1756 |
var cmd = connection.GetSqlStringCommand(query); |
1757 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
1758 |
AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString()); |
1759 |
|
1760 |
if (string.IsNullOrEmpty(row["XCOORDS"].ToString())) |
1761 |
AddWithValue(cmd, "@XCOORDS", DBNull.Value); |
1762 |
else |
1763 |
AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString()); |
1764 |
|
1765 |
if (string.IsNullOrEmpty(row["YCOORDS"].ToString())) |
1766 |
AddWithValue(cmd, "@YCOORDS", DBNull.Value); |
1767 |
else |
1768 |
AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString()); |
1769 |
|
1770 |
connection.ExecuteNonQuery(cmd, txn); |
1771 |
} |
1772 |
|
1773 |
// TopologySet |
1774 |
query = $"DELETE FROM {PSN_TOPOLOGYSET}"; |
1775 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1776 |
foreach (DataRow row in item.TopologySet.Rows) |
1777 |
{ |
1778 |
query = $"INSERT INTO {PSN_TOPOLOGYSET} (OID, Type, SubType, HeadItemTag, TailItemTag, HeadItemSPID, TailItemSPID) VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemSPID, @TailItemSPID)"; |
1779 |
var cmd = connection.GetSqlStringCommand(query); |
1780 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
1781 |
AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString()); |
1782 |
AddWithValue(cmd, "@SubType", string.IsNullOrEmpty(row["SubType"].ToString()) ? "" : row["SubType"].ToString()); |
1783 |
AddWithValue(cmd, "@HeadItemTag", string.IsNullOrEmpty(row["HeadItemTag"].ToString()) ? "" : row["HeadItemTag"].ToString()); |
1784 |
AddWithValue(cmd, "@TailItemTag", string.IsNullOrEmpty(row["TailItemTag"].ToString()) ? "" : row["TailItemTag"].ToString()); |
1785 |
AddWithValue(cmd, "@HeadItemSPID", string.IsNullOrEmpty(row["HeadItemSPID"].ToString()) ? "" : row["HeadItemSPID"].ToString()); |
1786 |
AddWithValue(cmd, "@TailItemSPID", string.IsNullOrEmpty(row["TailItemSPID"].ToString()) ? "" : row["TailItemSPID"].ToString()); |
1787 |
connection.ExecuteNonQuery(cmd, txn); |
1788 |
} |
1789 |
|
1790 |
// PSN |
1791 |
query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'"; |
1792 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1793 |
foreach (DataRow row in item.PipeSystemNetwork.Rows) |
1794 |
{ |
1795 |
query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} " + |
1796 |
$"(OID, Type, OrderNumber, Pipeline_OID, FROM_DATA, TO_DATA, TopologySet_OID_Key, PSNRevisionNumber, PBS, Drawings, IsValid, Status, IncludingVirtualData, PSNAccuracy) VALUES " + |
1797 |
$"(@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber, @PBS, @Drawings, @IsValid, @Status, @IncludingVirtualData, @PSNAccuracy)"; |
1798 |
var cmd = connection.GetSqlStringCommand(query); |
1799 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
1800 |
AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString()); |
1801 |
AddWithValue(cmd, "@OrderNumber", string.IsNullOrEmpty(row["OrderNumber"].ToString()) ? "" : row["OrderNumber"].ToString()); |
1802 |
AddWithValue(cmd, "@Pipeline_OID", string.IsNullOrEmpty(row["Pipeline_OID"].ToString()) ? "" : row["Pipeline_OID"].ToString()); |
1803 |
AddWithValue(cmd, "@FROM_DATA", string.IsNullOrEmpty(row["FROM_DATA"].ToString()) ? "" : row["FROM_DATA"].ToString()); |
1804 |
AddWithValue(cmd, "@TO_DATA", string.IsNullOrEmpty(row["TO_DATA"].ToString()) ? "" : row["TO_DATA"].ToString()); |
1805 |
AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString()); |
1806 |
AddWithValue(cmd, "@PSNRevisionNumber", string.IsNullOrEmpty(row["PSNRevisionNumber"].ToString()) ? "" : row["PSNRevisionNumber"].ToString()); |
1807 |
|
1808 |
int IsValid = 0; |
1809 |
if (row["IsValid"].ToString() == string.Empty || row["IsValid"].ToString() == "OK") |
1810 |
IsValid = 0; |
1811 |
else if (row["IsValid"].ToString() == "InValid") |
1812 |
IsValid = 1; |
1813 |
else if (row["IsValid"].ToString() == "Error") |
1814 |
IsValid = -1; |
1815 |
|
1816 |
AddWithValue(cmd, "@IsValid", IsValid); |
1817 |
AddWithValue(cmd, "@Status", string.IsNullOrEmpty(row["Status"].ToString()) ? "" : row["Status"].ToString()); |
1818 |
|
1819 |
AddWithValue(cmd, "@PBS", string.IsNullOrEmpty(row["PBS"].ToString()) ? "" : row["PBS"].ToString()); |
1820 |
AddWithValue(cmd, "@Drawings", string.IsNullOrEmpty(row["Drawings"].ToString()) ? "" : row["Drawings"].ToString()); |
1821 |
|
1822 |
AddWithValue(cmd, "@IncludingVirtualData", string.IsNullOrEmpty(row["IncludingVirtualData"].ToString()) ? "" : row["IncludingVirtualData"].ToString()); |
1823 |
if (string.IsNullOrEmpty(row["PSNAccuracy"].ToString())) |
1824 |
AddWithValue(cmd, "@PSNAccuracy", DBNull.Value); |
1825 |
else |
1826 |
AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString()); |
1827 |
|
1828 |
connection.ExecuteNonQuery(cmd, txn); |
1829 |
} |
1830 |
|
1831 |
//Pipeline |
1832 |
query = $"DELETE FROM {PSN_PIPELINE}"; |
1833 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1834 |
foreach (DataRow row in item.PipeLine.Rows) |
1835 |
{ |
1836 |
query = $"INSERT INTO {PSN_PIPELINE} (OID, PipeSystem_OID, FLUID, PMC, SEQNUMBER, INSULATION, FROM_DATA, TO_DATA, Unit) VALUES (@OID, @PipeSystem_OID, @FLUID, @PMC, @SEQNUMBER, @INSULATION, @FROM_DATA, @TO_DATA, @Unit)"; |
1837 |
var cmd = connection.GetSqlStringCommand(query); |
1838 |
AddWithValue(cmd, "@OID", row["OID"].ToString()); |
1839 |
AddWithValue(cmd, "@PipeSystem_OID", row["PipeSystem_OID"].ToString()); |
1840 |
AddWithValue(cmd, "@FLUID", row["FLUID"].ToString()); |
1841 |
AddWithValue(cmd, "@PMC", row["PMC"].ToString()); |
1842 |
AddWithValue(cmd, "@SEQNUMBER", row["SEQNUMBER"].ToString()); |
1843 |
AddWithValue(cmd, "@INSULATION", row["INSULATION"].ToString()); |
1844 |
AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString()); |
1845 |
AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString()); |
1846 |
AddWithValue(cmd, "@Unit", row["Unit"].ToString()); |
1847 |
connection.ExecuteNonQuery(cmd, txn); |
1848 |
} |
1849 |
|
1850 |
//PipeSystem |
1851 |
query = $"DELETE FROM {PSN_PIPESYSTEM}"; |
1852 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1853 |
foreach (DataRow row in item.PipeSystem.Rows) |
1854 |
{ |
1855 |
query = $"INSERT INTO {PSN_PIPESYSTEM} (OID, DESCRIPTION, FLUID, PMC, PipeLineQty, GroundLevel) VALUES (@OID, @DESCRIPTION, @FLUID, @PMC, @PipeLineQty, @GroundLevel)"; |
1856 |
var cmd = connection.GetSqlStringCommand(query); |
1857 |
AddWithValue(cmd, "@OID", row["OID"].ToString()); |
1858 |
AddWithValue(cmd, "@DESCRIPTION", row["DESCRIPTION"].ToString()); |
1859 |
AddWithValue(cmd, "@FLUID", row["FLUID"].ToString()); |
1860 |
AddWithValue(cmd, "@PMC", row["PMC"].ToString()); |
1861 |
AddWithValue(cmd, "@PipeLineQty", row["PipeLineQty"].ToString()); |
1862 |
AddWithValue(cmd, "@GroundLevel", row["GroundLevel"].ToString()); |
1863 |
connection.ExecuteNonQuery(cmd, txn); |
1864 |
} |
1865 |
|
1866 |
if(id2Info.ID2DBType == ID2DB_Type.MSSQL) |
1867 |
{ |
1868 |
query = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]"; |
1869 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1870 |
} |
1871 |
|
1872 |
|
1873 |
txn.Commit(); |
1874 |
} |
1875 |
catch (Exception ex) |
1876 |
{ |
1877 |
txn.Rollback(); |
1878 |
result = false; |
1879 |
} |
1880 |
|
1881 |
} |
1882 |
void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames) |
1883 |
{ |
1884 |
bool check = false; |
1885 |
if (colnames != null) |
1886 |
{ |
1887 |
foreach (KeyValuePair<string, string> col in dicCol) |
1888 |
{ |
1889 |
check = false; |
1890 |
foreach (string c in colnames) |
1891 |
{ |
1892 |
if (col.Key.Contains(c)) |
1893 |
{ |
1894 |
check = true; |
1895 |
break; |
1896 |
} |
1897 |
} |
1898 |
|
1899 |
if (!check) //없으면 추가 |
1900 |
{ |
1901 |
string i = string.Empty; |
1902 |
if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL")) |
1903 |
i = "DEFAULT 0"; |
1904 |
|
1905 |
var queryalter = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";"; |
1906 |
using (var cmd = connection.GetSqlStringCommand(queryalter)) |
1907 |
{ |
1908 |
cmd.ExecuteNonQuery(); |
1909 |
} |
1910 |
} |
1911 |
} |
1912 |
} |
1913 |
} |
1914 |
} |
1915 |
catch (Exception ex) |
1916 |
{ |
1917 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
1918 |
result = false; |
1919 |
} |
1920 |
} |
1921 |
|
1922 |
return result; |
1923 |
} |
1924 |
|
1925 |
public static bool SavePSNFluidCode(DataTable dt) |
1926 |
{ |
1927 |
ID2Info id2Info = ID2Info.GetInstance(); |
1928 |
|
1929 |
bool result = true; |
1930 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
1931 |
{ |
1932 |
try |
1933 |
{ |
1934 |
using (var txn = connection.BeginTransaction()) |
1935 |
{ |
1936 |
try |
1937 |
{ |
1938 |
var query = $"DELETE FROM {PSN_FLUIDCODE}"; |
1939 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
1940 |
|
1941 |
foreach (DataRow row in dt.Rows) |
1942 |
{ |
1943 |
query = $"INSERT INTO {PSN_FLUIDCODE} (UID, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)"; |
1944 |
var cmd = connection.GetSqlStringCommand(query); |
1945 |
cmd.Parameters.Clear(); |
1946 |
|
1947 |
{ |
1948 |
var param = cmd.CreateParameter(); |
1949 |
param.ParameterName = "@UID"; |
1950 |
param.Value = row["UID"].ToString(); |
1951 |
cmd.Parameters.Add(param); |
1952 |
} |
1953 |
|
1954 |
{ |
1955 |
var param = cmd.CreateParameter(); |
1956 |
param.ParameterName = "@Code"; |
1957 |
param.Value = row["Code"].ToString(); |
1958 |
cmd.Parameters.Add(param); |
1959 |
} |
1960 |
|
1961 |
{ |
1962 |
var param = cmd.CreateParameter(); |
1963 |
param.ParameterName = "@Description"; |
1964 |
param.Value = row["Description"].ToString(); |
1965 |
cmd.Parameters.Add(param); |
1966 |
} |
1967 |
|
1968 |
{ |
1969 |
var param = cmd.CreateParameter(); |
1970 |
param.ParameterName = "@Condition"; |
1971 |
param.Value = row["Condition"].ToString(); |
1972 |
cmd.Parameters.Add(param); |
1973 |
} |
1974 |
|
1975 |
{ |
1976 |
var param = cmd.CreateParameter(); |
1977 |
param.ParameterName = "@Remarks"; |
1978 |
param.Value = row["Remarks"].ToString(); |
1979 |
cmd.Parameters.Add(param); |
1980 |
} |
1981 |
|
1982 |
{ |
1983 |
var param = cmd.CreateParameter(); |
1984 |
param.ParameterName = "@GroundLevel"; |
1985 |
param.Value = row["GroundLevel"].ToString(); |
1986 |
cmd.Parameters.Add(param); |
1987 |
} |
1988 |
|
1989 |
connection.ExecuteNonQuery(cmd, txn); |
1990 |
} |
1991 |
txn.Commit(); |
1992 |
} |
1993 |
catch (Exception ex) |
1994 |
{ |
1995 |
txn.Rollback(); |
1996 |
result = false; |
1997 |
} |
1998 |
} |
1999 |
} |
2000 |
catch (Exception ex) |
2001 |
{ |
2002 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
2003 |
result = false; |
2004 |
} |
2005 |
} |
2006 |
|
2007 |
return result; |
2008 |
} |
2009 |
|
2010 |
public static DataTable SelectPSNFluidCode() |
2011 |
{ |
2012 |
DataTable dt = null; |
2013 |
ID2Info id2Info = ID2Info.GetInstance(); |
2014 |
|
2015 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2016 |
{ |
2017 |
try |
2018 |
{ |
2019 |
var query = $"SELECT * FROM {PSN_FLUIDCODE}"; |
2020 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2021 |
{ |
2022 |
dt = ds.Tables[0].Copy(); |
2023 |
} |
2024 |
} |
2025 |
catch (Exception ex) |
2026 |
{ |
2027 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2028 |
} |
2029 |
} |
2030 |
|
2031 |
return dt; |
2032 |
} |
2033 |
|
2034 |
public static bool SavePSNPMC(DataTable dt) |
2035 |
{ |
2036 |
ID2Info id2Info = ID2Info.GetInstance(); |
2037 |
|
2038 |
bool result = true; |
2039 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2040 |
{ |
2041 |
try |
2042 |
{ |
2043 |
using (var txn = connection.BeginTransaction()) |
2044 |
{ |
2045 |
try |
2046 |
{ |
2047 |
var query = $"DELETE FROM {PSN_PIPINGMATLCLASS}"; |
2048 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
2049 |
|
2050 |
foreach (DataRow row in dt.Rows) |
2051 |
{ |
2052 |
query = $"INSERT INTO {PSN_PIPINGMATLCLASS} ( UID, Priority, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)"; |
2053 |
var cmd = connection.GetSqlStringCommand(query); |
2054 |
cmd.Parameters.Clear(); |
2055 |
|
2056 |
{ |
2057 |
var param = cmd.CreateParameter(); |
2058 |
param.ParameterName = "@UID"; |
2059 |
param.Value = row["UID"].ToString(); |
2060 |
cmd.Parameters.Add(param); |
2061 |
} |
2062 |
|
2063 |
{ |
2064 |
var param = cmd.CreateParameter(); |
2065 |
param.ParameterName = "@Priority"; |
2066 |
param.Value = row["Priority"].ToString(); |
2067 |
cmd.Parameters.Add(param); |
2068 |
} |
2069 |
|
2070 |
{ |
2071 |
var param = cmd.CreateParameter(); |
2072 |
param.ParameterName = "@Code"; |
2073 |
param.Value = row["Code"].ToString(); |
2074 |
cmd.Parameters.Add(param); |
2075 |
} |
2076 |
|
2077 |
{ |
2078 |
var param = cmd.CreateParameter(); |
2079 |
param.ParameterName = "@Description"; |
2080 |
param.Value = row["Description"].ToString(); |
2081 |
cmd.Parameters.Add(param); |
2082 |
} |
2083 |
|
2084 |
{ |
2085 |
var param = cmd.CreateParameter(); |
2086 |
param.ParameterName = "@Condition"; |
2087 |
param.Value = row["Condition"].ToString(); |
2088 |
cmd.Parameters.Add(param); |
2089 |
} |
2090 |
|
2091 |
{ |
2092 |
var param = cmd.CreateParameter(); |
2093 |
param.ParameterName = "@Remarks"; |
2094 |
param.Value = row["Remarks"].ToString(); |
2095 |
cmd.Parameters.Add(param); |
2096 |
} |
2097 |
|
2098 |
{ |
2099 |
var param = cmd.CreateParameter(); |
2100 |
param.ParameterName = "@GroundLevel"; |
2101 |
param.Value = row["GroundLevel"].ToString(); |
2102 |
cmd.Parameters.Add(param); |
2103 |
} |
2104 |
|
2105 |
connection.ExecuteNonQuery(cmd, txn); |
2106 |
} |
2107 |
|
2108 |
txn.Commit(); |
2109 |
} |
2110 |
catch (Exception ex) |
2111 |
{ |
2112 |
txn.Rollback(); |
2113 |
result = false; |
2114 |
} |
2115 |
} |
2116 |
} |
2117 |
catch (Exception ex) |
2118 |
{ |
2119 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
2120 |
result = false; |
2121 |
} |
2122 |
} |
2123 |
|
2124 |
return result; |
2125 |
} |
2126 |
|
2127 |
public static bool SavePSNInsulation(DataTable dt) |
2128 |
{ |
2129 |
ID2Info id2Info = ID2Info.GetInstance(); |
2130 |
|
2131 |
bool result = true; |
2132 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2133 |
{ |
2134 |
try |
2135 |
{ |
2136 |
using (var txn = connection.BeginTransaction()) |
2137 |
{ |
2138 |
try |
2139 |
{ |
2140 |
var query = $"DELETE FROM {PSN_INSULATIONPURPOSE}"; |
2141 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
2142 |
|
2143 |
foreach (DataRow row in dt.Rows) |
2144 |
{ |
2145 |
query = $"INSERT INTO {PSN_INSULATIONPURPOSE} (UID, Code, Description, Remarks) VALUES (@UID, @Code, @Description, @Remarks)"; |
2146 |
var cmd = connection.GetSqlStringCommand(query); |
2147 |
cmd.Parameters.Clear(); |
2148 |
|
2149 |
{ |
2150 |
var param = cmd.CreateParameter(); |
2151 |
param.ParameterName = "@UID"; |
2152 |
param.Value = row["UID"].ToString(); |
2153 |
cmd.Parameters.Add(param); |
2154 |
} |
2155 |
|
2156 |
{ |
2157 |
var param = cmd.CreateParameter(); |
2158 |
param.ParameterName = "@Code"; |
2159 |
param.Value = row["Code"].ToString(); |
2160 |
cmd.Parameters.Add(param); |
2161 |
} |
2162 |
|
2163 |
{ |
2164 |
var param = cmd.CreateParameter(); |
2165 |
param.ParameterName = "@Description"; |
2166 |
param.Value = row["Description"].ToString(); |
2167 |
cmd.Parameters.Add(param); |
2168 |
} |
2169 |
|
2170 |
{ |
2171 |
var param = cmd.CreateParameter(); |
2172 |
param.ParameterName = "@Remarks"; |
2173 |
param.Value = row["Remarks"].ToString(); |
2174 |
cmd.Parameters.Add(param); |
2175 |
} |
2176 |
|
2177 |
connection.ExecuteNonQuery(cmd, txn); |
2178 |
} |
2179 |
|
2180 |
txn.Commit(); |
2181 |
} |
2182 |
catch (Exception ex) |
2183 |
{ |
2184 |
txn.Rollback(); |
2185 |
result = false; |
2186 |
} |
2187 |
} |
2188 |
} |
2189 |
catch (Exception ex) |
2190 |
{ |
2191 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
2192 |
result = false; |
2193 |
} |
2194 |
} |
2195 |
|
2196 |
return result; |
2197 |
} |
2198 |
|
2199 |
public static PSN GetDBPSN() |
2200 |
{ |
2201 |
PSN result = new PSN(); |
2202 |
ID2Info id2Info = ID2Info.GetInstance(); |
2203 |
|
2204 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2205 |
{ |
2206 |
try |
2207 |
{ |
2208 |
//query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK}"; |
2209 |
//using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2210 |
//{ |
2211 |
// result.PipeSystemNetwork = ds.Tables[0].Copy(); |
2212 |
//} |
2213 |
|
2214 |
var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'"; |
2215 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2216 |
{ |
2217 |
result.PipeSystemNetwork = ds.Tables[0].Clone(); |
2218 |
result.PipeSystemNetwork.Columns["IsValid"].DataType = typeof(string); |
2219 |
|
2220 |
foreach (DataRow row in ds.Tables[0].Rows) |
2221 |
{ |
2222 |
DataRow newRow = result.PipeSystemNetwork.NewRow(); |
2223 |
newRow["OID"] = row["OID"].ToString(); |
2224 |
newRow["Type"] = row["Type"].ToString(); |
2225 |
newRow["OrderNumber"] = row["OrderNumber"].ToString(); |
2226 |
newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString(); |
2227 |
newRow["FROM_DATA"] = row["FROM_DATA"].ToString(); |
2228 |
newRow["TO_DATA"] = row["TO_DATA"].ToString(); |
2229 |
newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString(); |
2230 |
newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString(); |
2231 |
|
2232 |
string IsValid = string.Empty; |
2233 |
|
2234 |
if (Convert.ToInt32(row["IsValid"].ToString()) == 0) |
2235 |
IsValid = string.Empty;//"OK"; |
2236 |
else if (Convert.ToInt32(row["IsValid"].ToString()) == 1) |
2237 |
IsValid = "InValid"; |
2238 |
else if (Convert.ToInt32(row["IsValid"].ToString()) == -1) |
2239 |
IsValid = "Error"; |
2240 |
|
2241 |
newRow["IsValid"] = IsValid; |
2242 |
|
2243 |
newRow["Status"] = row["Status"].ToString(); |
2244 |
newRow["PBS"] = row["PBS"].ToString(); |
2245 |
newRow["Drawings"] = row["Drawings"].ToString(); |
2246 |
|
2247 |
newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString(); |
2248 |
newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString(); |
2249 |
|
2250 |
result.PipeSystemNetwork.Rows.Add(newRow); |
2251 |
} |
2252 |
} |
2253 |
|
2254 |
query = $"SELECT * FROM {PSN_EQUIPMENT}"; |
2255 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2256 |
{ |
2257 |
result.Equipment = ds.Tables[0].Copy(); |
2258 |
} |
2259 |
|
2260 |
query = $"SELECT * FROM {PSN_NOZZLE}"; |
2261 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2262 |
{ |
2263 |
result.Nozzle = ds.Tables[0].Copy(); |
2264 |
} |
2265 |
|
2266 |
query = $"SELECT * FROM {PSN_PATHITEMS}"; |
2267 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2268 |
{ |
2269 |
result.PathItems = ds.Tables[0].Copy(); |
2270 |
} |
2271 |
|
2272 |
query = $"SELECT * FROM {PSN_SEQUENCEDATA}"; |
2273 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2274 |
{ |
2275 |
result.SequenceData = ds.Tables[0].Copy(); |
2276 |
} |
2277 |
|
2278 |
query = $"SELECT * FROM {PSN_TOPOLOGYSET}"; |
2279 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2280 |
{ |
2281 |
result.TopologySet = ds.Tables[0].Copy(); |
2282 |
} |
2283 |
|
2284 |
query = $"SELECT * FROM {PSN_PIPELINE}"; |
2285 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2286 |
{ |
2287 |
result.PipeLine = ds.Tables[0].Copy(); |
2288 |
} |
2289 |
|
2290 |
query = $"SELECT * FROM {PSN_PIPESYSTEM}"; |
2291 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2292 |
{ |
2293 |
result.PipeSystem = ds.Tables[0].Copy(); |
2294 |
} |
2295 |
|
2296 |
result.Revision = GetRevision(); |
2297 |
} |
2298 |
catch (Exception ex) |
2299 |
{ |
2300 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
2301 |
result = null; |
2302 |
} |
2303 |
} |
2304 |
|
2305 |
return result; |
2306 |
} |
2307 |
|
2308 |
public static int GetRevision() |
2309 |
{ |
2310 |
int result = 0; |
2311 |
ID2Info id2Info = ID2Info.GetInstance(); |
2312 |
|
2313 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2314 |
{ |
2315 |
try |
2316 |
{ |
2317 |
var query = $"SELECT DISTINCT PSNRevisionNumber FROM {PSN_PIPESYSTEMNETWORK};"; |
2318 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2319 |
{ |
2320 |
foreach (DataRow row in ds.Tables[0].Rows) |
2321 |
{ |
2322 |
string value = row["PSNRevisionNumber"].ToString(); |
2323 |
if (value.StartsWith("V")) |
2324 |
value = value.Remove(0, 1); |
2325 |
int revisionNumber = Convert.ToInt32(value); |
2326 |
if (result < revisionNumber) |
2327 |
result = revisionNumber; |
2328 |
} |
2329 |
} |
2330 |
} |
2331 |
catch (Exception ex) |
2332 |
{ |
2333 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2334 |
result = -1; |
2335 |
} |
2336 |
} |
2337 |
|
2338 |
return result; |
2339 |
} |
2340 |
|
2341 |
public static DataTable GetPathItem() |
2342 |
{ |
2343 |
DataTable dt = null; |
2344 |
|
2345 |
ID2Info id2Info = ID2Info.GetInstance(); |
2346 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2347 |
{ |
2348 |
try |
2349 |
{ |
2350 |
var query = $"SELECT * FROM {PSN_PATHITEMS}"; |
2351 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2352 |
{ |
2353 |
dt = ds.Tables[0].Copy(); |
2354 |
} |
2355 |
} |
2356 |
catch (Exception ex) |
2357 |
{ |
2358 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2359 |
} |
2360 |
} |
2361 |
|
2362 |
return dt; |
2363 |
} |
2364 |
|
2365 |
public static DataTable GetTopologySet() |
2366 |
{ |
2367 |
DataTable dt = null; |
2368 |
|
2369 |
ID2Info id2Info = ID2Info.GetInstance(); |
2370 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2371 |
{ |
2372 |
try |
2373 |
{ |
2374 |
var query = $"SELECT * FROM {PSN_TOPOLOGYSET}"; |
2375 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2376 |
{ |
2377 |
dt = ds.Tables[0].Clone(); |
2378 |
foreach (DataRow row in ds.Tables[0].Rows) |
2379 |
{ |
2380 |
DataRow newRow = dt.NewRow(); |
2381 |
newRow["OID"] = row["OID"].ToString(); |
2382 |
newRow["Type"] = row["Type"].ToString(); |
2383 |
newRow["SubType"] = row["SubType"].ToString(); |
2384 |
newRow["HeadItemTag"] = row["HeadItemTag"].ToString(); |
2385 |
newRow["TailItemTag"] = row["TailItemTag"].ToString(); |
2386 |
newRow["HeadItemSPID"] = row["HeadItemSPID"].ToString(); |
2387 |
newRow["TailItemSPID"] = row["TailItemSPID"].ToString(); |
2388 |
dt.Rows.Add(newRow); |
2389 |
} |
2390 |
} |
2391 |
} |
2392 |
catch (Exception ex) |
2393 |
{ |
2394 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2395 |
} |
2396 |
} |
2397 |
|
2398 |
return dt; |
2399 |
} |
2400 |
|
2401 |
public static DataTable GetPipeSystemNetwork() |
2402 |
{ |
2403 |
DataTable dt = null; |
2404 |
|
2405 |
ID2Info id2Info = ID2Info.GetInstance(); |
2406 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2407 |
{ |
2408 |
try |
2409 |
{ |
2410 |
var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}' ORDER BY OID, OrderNumber"; |
2411 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2412 |
{ |
2413 |
dt = ds.Tables[0].Clone(); |
2414 |
dt.Columns["IsValid"].DataType = typeof(string); |
2415 |
foreach (DataRow row in ds.Tables[0].Rows) |
2416 |
{ |
2417 |
DataRow newRow = dt.NewRow(); |
2418 |
newRow["OID"] = row["OID"].ToString(); |
2419 |
newRow["Type"] = row["Type"].ToString(); |
2420 |
newRow["OrderNumber"] = row["OrderNumber"].ToString(); |
2421 |
newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString(); |
2422 |
newRow["FROM_DATA"] = row["FROM_DATA"].ToString(); |
2423 |
newRow["TO_DATA"] = row["TO_DATA"].ToString(); |
2424 |
newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString(); |
2425 |
newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString(); |
2426 |
|
2427 |
string IsValid = string.Empty; |
2428 |
|
2429 |
if (Convert.ToInt32(row["IsValid"].ToString()) == 0) |
2430 |
IsValid = string.Empty;//"OK"; |
2431 |
else if (Convert.ToInt32(row["IsValid"].ToString()) == 1) |
2432 |
IsValid = "InValid"; |
2433 |
else if (Convert.ToInt32(row["IsValid"].ToString()) == -1) |
2434 |
IsValid = "Error"; |
2435 |
|
2436 |
newRow["IsValid"] = IsValid; |
2437 |
newRow["Status"] = row["Status"].ToString(); |
2438 |
|
2439 |
newRow["PBS"] = row["PBS"].ToString(); |
2440 |
newRow["Drawings"] = row["Drawings"].ToString(); |
2441 |
|
2442 |
newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString(); |
2443 |
newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString(); |
2444 |
|
2445 |
dt.Rows.Add(newRow); |
2446 |
} |
2447 |
} |
2448 |
} |
2449 |
catch (Exception ex) |
2450 |
{ |
2451 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2452 |
} |
2453 |
} |
2454 |
|
2455 |
return dt; |
2456 |
} |
2457 |
|
2458 |
public static DataTable GetSequenceData() |
2459 |
{ |
2460 |
DataTable dt = null; |
2461 |
|
2462 |
ID2Info id2Info = ID2Info.GetInstance(); |
2463 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2464 |
{ |
2465 |
try |
2466 |
{ |
2467 |
var query = $"SELECT * FROM {PSN_SEQUENCEDATA}"; |
2468 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
2469 |
{ |
2470 |
dt = ds.Tables[0].Copy(); |
2471 |
} |
2472 |
} |
2473 |
catch (Exception ex) |
2474 |
{ |
2475 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2476 |
} |
2477 |
} |
2478 |
|
2479 |
return dt; |
2480 |
} |
2481 |
|
2482 |
|
2483 |
//Anohter DB |
2484 |
public static bool ConnTestAndCreateAnotherTable() |
2485 |
{ |
2486 |
bool result = false; |
2487 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
2488 |
|
2489 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2490 |
{ |
2491 |
try |
2492 |
{ |
2493 |
var names = connection.GetTableNames(); |
2494 |
var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING); |
2495 |
Dictionary<string, string> dicColCheck = new Dictionary<string, string>(); |
2496 |
dicColCheck.Add("GROUP_ID", "TEXT"); |
2497 |
dicColCheck.Add("DESCRIPTION", "TEXT"); |
2498 |
dicColCheck.Add("INDEX", "INTEGER"); |
2499 |
dicColCheck.Add("NAME", "TEXT"); |
2500 |
|
2501 |
if (matched == null) |
2502 |
{ |
2503 |
var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)"; |
2504 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2505 |
{ |
2506 |
cmd.ExecuteNonQuery(); |
2507 |
} |
2508 |
} |
2509 |
else |
2510 |
{ |
2511 |
AddColumn(PSN_HEADER_SETTING, dicColCheck); |
2512 |
} |
2513 |
|
2514 |
matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING); |
2515 |
dicColCheck.Clear(); |
2516 |
dicColCheck.Add("GROUP_ID", "TEXT"); |
2517 |
dicColCheck.Add("DESCRIPTION", "TEXT"); |
2518 |
dicColCheck.Add("INDEX", "INTEGER"); |
2519 |
dicColCheck.Add("NAME", "TEXT"); |
2520 |
if (matched == null) |
2521 |
{ |
2522 |
var query = $"CREATE TABLE {PSN_VENTDRAIN_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)"; |
2523 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2524 |
{ |
2525 |
cmd.ExecuteNonQuery(); |
2526 |
} |
2527 |
} |
2528 |
else |
2529 |
{ |
2530 |
AddColumn(PSN_VENTDRAIN_SETTING, dicColCheck); |
2531 |
} |
2532 |
|
2533 |
matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE); |
2534 |
dicColCheck.Clear(); |
2535 |
dicColCheck.Add("UID", "TEXT"); |
2536 |
if (matched == null) |
2537 |
{ |
2538 |
var query = $"CREATE TABLE {PSN_TOPOLOGY_RULE} (UID TEXT)"; |
2539 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2540 |
{ |
2541 |
cmd.ExecuteNonQuery(); |
2542 |
} |
2543 |
|
2544 |
DataTable topologyRule = new DataTable(); |
2545 |
topologyRule.Columns.Add("NAME", typeof(string)); |
2546 |
|
2547 |
topologyRule.Rows.Add("FluidCode"); |
2548 |
topologyRule.Rows.Add("-"); |
2549 |
topologyRule.Rows.Add("PipingMaterialsClass"); |
2550 |
topologyRule.Rows.Add("-"); |
2551 |
topologyRule.Rows.Add("Tag Seq No"); |
2552 |
|
2553 |
SaveTopologyRule(topologyRule); |
2554 |
} |
2555 |
//else |
2556 |
//{ |
2557 |
// AddColumn(PSN_TOPOLOGY_RULE, dicColCheck); |
2558 |
//} |
2559 |
|
2560 |
matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK); |
2561 |
dicColCheck.Clear(); |
2562 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2563 |
dicColCheck.Add("Type", "NVARCHAR(255)"); |
2564 |
dicColCheck.Add("OrderNumber", "NVARCHAR(255)"); |
2565 |
dicColCheck.Add("Pipeline_OID", "NVARCHAR(255)"); |
2566 |
dicColCheck.Add("From_Data", "NVARCHAR(255)"); |
2567 |
dicColCheck.Add("To_Data", "NVARCHAR(255)"); |
2568 |
dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(125)"); |
2569 |
dicColCheck.Add("PSNRevisionNumber", "NVARCHAR(255)"); |
2570 |
dicColCheck.Add("IsValid", "INT"); |
2571 |
dicColCheck.Add("Status", "NVARCHAR(255)"); |
2572 |
dicColCheck.Add("PBS", "NVARCHAR(255)"); |
2573 |
dicColCheck.Add("Drawings", "NVARCHAR(255)"); |
2574 |
dicColCheck.Add("IncludingVirtualData", "NVARCHAR(10)"); |
2575 |
dicColCheck.Add("PSNAccuracy", "REAL"); |
2576 |
|
2577 |
if (matched == null) |
2578 |
{ |
2579 |
var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(255), Type NVARCHAR(255), OrderNumber NVARCHAR(255), Pipeline_OID NVARCHAR(255), From_Data NVARCHAR(255), " + |
2580 |
"To_Data NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), IsValid INTEGER, Status NVARCHAR(255), PBS NVARCHAR(255), Drawings NVARCHAR(255), " + |
2581 |
"IncludingVirtualData NVARCHAR(10), PSNAccuracy REAL)"; |
2582 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2583 |
{ |
2584 |
cmd.ExecuteNonQuery(); |
2585 |
} |
2586 |
} |
2587 |
else |
2588 |
{ |
2589 |
AddColumn(PSN_PIPESYSTEMNETWORK, dicColCheck); |
2590 |
} |
2591 |
|
2592 |
matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT); |
2593 |
dicColCheck.Clear(); |
2594 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2595 |
dicColCheck.Add("ItemTag", "NVARCHAR(255)"); |
2596 |
dicColCheck.Add("Xcoords", "REAL"); |
2597 |
dicColCheck.Add("Ycoords", "REAL"); |
2598 |
if (matched == null) |
2599 |
{ |
2600 |
var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL)"; |
2601 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2602 |
{ |
2603 |
cmd.ExecuteNonQuery(); |
2604 |
} |
2605 |
} |
2606 |
else |
2607 |
{ |
2608 |
AddColumn(PSN_EQUIPMENT, dicColCheck); |
2609 |
} |
2610 |
|
2611 |
dicColCheck.Clear(); |
2612 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2613 |
dicColCheck.Add("ItemTag", "NVARCHAR(255)"); |
2614 |
dicColCheck.Add("Xcoords", "REAL"); |
2615 |
dicColCheck.Add("Ycoords", "REAL"); |
2616 |
dicColCheck.Add("Equipment_OID", "NVARCHAR(255)"); |
2617 |
dicColCheck.Add("Fluid", "NVARCHAR(255)"); |
2618 |
dicColCheck.Add("NPD", "NVARCHAR(255)"); |
2619 |
dicColCheck.Add("PMC", "NVARCHAR(255)"); |
2620 |
dicColCheck.Add("Rotation", "REAL"); |
2621 |
dicColCheck.Add("FlowDirection", "NVARCHAR(255)"); |
2622 |
|
2623 |
matched = names.FirstOrDefault(param => param == PSN_NOZZLE); |
2624 |
if (matched == null) |
2625 |
{ |
2626 |
var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL, Equipment_OID NVARCHAR(255), " + |
2627 |
"Fluid NVARCHAR(255), NPD NVARCHAR(255), PMC NVARCHAR(255), Rotation REAL, FlowDirection NVARCHAR(255))"; |
2628 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2629 |
{ |
2630 |
cmd.ExecuteNonQuery(); |
2631 |
} |
2632 |
} |
2633 |
else |
2634 |
{ |
2635 |
AddColumn(PSN_NOZZLE, dicColCheck); |
2636 |
} |
2637 |
|
2638 |
matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE); |
2639 |
dicColCheck.Clear(); |
2640 |
dicColCheck.Add("UID", "NVARCHAR(50)"); |
2641 |
dicColCheck.Add("Code", "NVARCHAR(255)"); |
2642 |
dicColCheck.Add("Description", "NVARCHAR(255)"); |
2643 |
dicColCheck.Add("Condition", "NVARCHAR(255)"); |
2644 |
dicColCheck.Add("Remarks", "NVARCHAR(255)"); |
2645 |
dicColCheck.Add("GroundLevel", "NVARCHAR(20)"); |
2646 |
if (matched == null) |
2647 |
{ |
2648 |
var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))"; |
2649 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2650 |
{ |
2651 |
cmd.ExecuteNonQuery(); |
2652 |
} |
2653 |
} |
2654 |
else |
2655 |
{ |
2656 |
AddColumn(PSN_FLUIDCODE, dicColCheck); |
2657 |
} |
2658 |
|
2659 |
matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS); |
2660 |
dicColCheck.Clear(); |
2661 |
dicColCheck.Add("UID", "NVARCHAR(50)"); |
2662 |
dicColCheck.Add("Priority", "INTEGER"); |
2663 |
dicColCheck.Add("Code", "NVARCHAR(255)"); |
2664 |
dicColCheck.Add("Description", "NVARCHAR(255)"); |
2665 |
dicColCheck.Add("Condition", "NVARCHAR(255)"); |
2666 |
dicColCheck.Add("Remarks", "NVARCHAR(255)"); |
2667 |
dicColCheck.Add("GroundLevel", "NVARCHAR(20)"); |
2668 |
if (matched == null) |
2669 |
{ |
2670 |
var query = $"CREATE TABLE {PSN_PIPINGMATLCLASS} (UID NVARCHAR(50), Priority INTEGER, Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))"; |
2671 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2672 |
{ |
2673 |
cmd.ExecuteNonQuery(); |
2674 |
} |
2675 |
} |
2676 |
else |
2677 |
{ |
2678 |
AddColumn(PSN_PIPINGMATLCLASS, dicColCheck); |
2679 |
} |
2680 |
|
2681 |
matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA); |
2682 |
dicColCheck.Clear(); |
2683 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2684 |
dicColCheck.Add("SERIALNUMBER", "NVARCHAR(255)"); |
2685 |
dicColCheck.Add("PathItem_OID", "NVARCHAR(255)"); |
2686 |
dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(255)"); |
2687 |
if (matched == null) |
2688 |
{ |
2689 |
var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(255), SERIALNUMBER NVARCHAR(255), PathItem_OID NVARCHAR(255), TopologySet_OID_Key NVARCHAR(255))"; |
2690 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2691 |
{ |
2692 |
cmd.ExecuteNonQuery(); |
2693 |
} |
2694 |
} |
2695 |
else |
2696 |
{ |
2697 |
AddColumn(PSN_SEQUENCEDATA, dicColCheck); |
2698 |
} |
2699 |
|
2700 |
matched = names.FirstOrDefault(param => param == PSN_PATHITEMS); |
2701 |
dicColCheck.Clear(); |
2702 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2703 |
dicColCheck.Add("SequenceData_OID", "NVARCHAR(255)"); |
2704 |
dicColCheck.Add("TopologySet_OID", "NVARCHAR(255)"); |
2705 |
dicColCheck.Add("BranchTopologySet_OID", "NVARCHAR(255)"); |
2706 |
dicColCheck.Add("PipeLine_OID", "NVARCHAR(255)"); |
2707 |
dicColCheck.Add("ItemName", "NVARCHAR(255)"); |
2708 |
dicColCheck.Add("ItemTag", "NVARCHAR(255)"); |
2709 |
dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)"); |
2710 |
dicColCheck.Add("CLASS", "NVARCHAR(255)"); |
2711 |
dicColCheck.Add("SUBCLASS", "NVARCHAR(255)"); |
2712 |
dicColCheck.Add("TYPE", "NVARCHAR(255)"); |
2713 |
dicColCheck.Add("PIDNAME", "NVARCHAR(255)"); |
2714 |
dicColCheck.Add("Equipment_OID", "NVARCHAR(255)"); |
2715 |
dicColCheck.Add("NPD", "NVARCHAR(255)"); |
2716 |
dicColCheck.Add("GROUPTAG", "NVARCHAR(255)"); |
2717 |
dicColCheck.Add("PipeSystemNetwork_OID", "NVARCHAR(255)"); |
2718 |
dicColCheck.Add("PipeRun_OID", "NVARCHAR(255)"); |
2719 |
dicColCheck.Add("ViewPipeSystemNetwork_OID", "NVARCHAR(255)"); |
2720 |
if (matched == null) |
2721 |
{ |
2722 |
var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(255), SequenceData_OID NVARCHAR(255), " + |
2723 |
"TopologySet_OID NVARCHAR(255), BranchTopologySet_OID NVARCHAR(255), PipeLine_OID NVARCHAR(255), ItemName NVARCHAR(255), ItemTag NVARCHAR(255), DESCRIPTION NVARCHAR(255), " + |
2724 |
"CLASS NVARCHAR(255), SUBCLASS NVARCHAR(255), TYPE NVARCHAR(255), PIDNAME NVARCHAR(255), Equipment_OID NVARCHAR(255), NPD NVARCHAR(255), GROUPTAG NVARCHAR(255), PipeSystemNetwork_OID NVARCHAR(255), PipeRun_OID NVARCHAR(255), " + |
2725 |
"ViewPipeSystemNetwork_OID NVARCHAR(255))"; |
2726 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2727 |
{ |
2728 |
cmd.ExecuteNonQuery(); |
2729 |
} |
2730 |
} |
2731 |
else |
2732 |
{ |
2733 |
AddColumn(PSN_PATHITEMS, dicColCheck); |
2734 |
} |
2735 |
|
2736 |
matched = names.FirstOrDefault(param => param == PSN_VIEW); |
2737 |
dicColCheck.Clear(); |
2738 |
dicColCheck.Add("OID", "TEXT"); |
2739 |
if (matched == null) |
2740 |
{ |
2741 |
var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)"; |
2742 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2743 |
{ |
2744 |
cmd.ExecuteNonQuery(); |
2745 |
} |
2746 |
} |
2747 |
|
2748 |
matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET); |
2749 |
dicColCheck.Clear(); |
2750 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2751 |
dicColCheck.Add("Type", "NVARCHAR(255)"); |
2752 |
dicColCheck.Add("SubType", "NVARCHAR(255)"); |
2753 |
dicColCheck.Add("HeadItemTag", "NVARCHAR(255)"); |
2754 |
dicColCheck.Add("TailItemTag", "NVARCHAR(255)"); |
2755 |
dicColCheck.Add("HeadItemSPID", "NVARCHAR(255)"); |
2756 |
dicColCheck.Add("TailItemSPID", "NVARCHAR(255)"); |
2757 |
|
2758 |
if (matched == null) |
2759 |
{ |
2760 |
var query = $"CREATE TABLE { PSN_TOPOLOGYSET} (OID NVARCHAR(255), Type NVARCHAR(255), SubType NVARCHAR(255), HeadItemTag NVARCHAR(255), TailItemTag NVARCHAR(255), HeadItemSPID NVARCHAR(255), TailItemSPID NVARCHAR(255))"; |
2761 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2762 |
{ |
2763 |
cmd.ExecuteNonQuery(); |
2764 |
} |
2765 |
} |
2766 |
else |
2767 |
{ |
2768 |
AddColumn(PSN_TOPOLOGYSET, dicColCheck); |
2769 |
} |
2770 |
|
2771 |
matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING); |
2772 |
dicColCheck.Clear(); |
2773 |
dicColCheck.Add("INDEX", "INTEGER"); |
2774 |
dicColCheck.Add("NAME", "TEXT"); |
2775 |
dicColCheck.Add("KEYWORD", "TEXT"); |
2776 |
if (matched == null) |
2777 |
{ |
2778 |
var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)"; |
2779 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2780 |
{ |
2781 |
cmd.ExecuteNonQuery(); |
2782 |
} |
2783 |
} |
2784 |
else |
2785 |
{ |
2786 |
AddColumn(PSN_TRANSFORMKEYWORD_SETTING, dicColCheck); |
2787 |
} |
2788 |
|
2789 |
matched = names.FirstOrDefault(param => param == PSN_PIPELINE); |
2790 |
dicColCheck.Clear(); |
2791 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2792 |
dicColCheck.Add("PipeSystem_OID", "NVARCHAR(255)"); |
2793 |
dicColCheck.Add("FLUID", "NVARCHAR(255)"); |
2794 |
dicColCheck.Add("PMC", "NVARCHAR(255)"); |
2795 |
dicColCheck.Add("SEQNUMBER", "NVARCHAR(255)"); |
2796 |
dicColCheck.Add("INSULATION", "NVARCHAR(255)"); |
2797 |
dicColCheck.Add("FROM_DATA", "NVARCHAR(255)"); |
2798 |
dicColCheck.Add("TO_DATA", "NVARCHAR(255)"); |
2799 |
dicColCheck.Add("Unit", "NVARCHAR(100)"); |
2800 |
if (matched == null) |
2801 |
{ |
2802 |
var query = $"CREATE TABLE {PSN_PIPELINE} (OID NVARCHAR(255), PipeSystem_OID NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), SEQNUMBER NVARCHAR(255), INSULATION NVARCHAR(255), " + |
2803 |
$"FROM_DATA NVARCHAR(255), TO_DATA NVARCHAR(255), Unit NVARCHAR(100))"; |
2804 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2805 |
{ |
2806 |
cmd.ExecuteNonQuery(); |
2807 |
} |
2808 |
} |
2809 |
else |
2810 |
{ |
2811 |
AddColumn(PSN_PIPELINE, dicColCheck); |
2812 |
} |
2813 |
|
2814 |
matched = names.FirstOrDefault(param => param == PSN_INSULATIONPURPOSE); |
2815 |
dicColCheck.Clear(); |
2816 |
dicColCheck.Add("UID", "NVARCHAR(50)"); |
2817 |
dicColCheck.Add("Code", "NVARCHAR(255)"); |
2818 |
dicColCheck.Add("Description", "NVARCHAR(255)"); |
2819 |
dicColCheck.Add("Remarks", "NVARCHAR(255)"); |
2820 |
if (matched == null) |
2821 |
{ |
2822 |
var query = $"CREATE TABLE {PSN_INSULATIONPURPOSE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Remarks NVARCHAR(255))"; |
2823 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2824 |
{ |
2825 |
cmd.ExecuteNonQuery(); |
2826 |
} |
2827 |
} |
2828 |
else |
2829 |
{ |
2830 |
AddColumn(PSN_INSULATIONPURPOSE, dicColCheck); |
2831 |
} |
2832 |
|
2833 |
matched = names.FirstOrDefault(param => param == PSN_VALVEGROUP_SETTING); |
2834 |
dicColCheck.Clear(); |
2835 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2836 |
dicColCheck.Add("GroupType", "NVARCHAR(255)"); |
2837 |
dicColCheck.Add("TagIdentifier", "NVARCHAR(50)"); |
2838 |
dicColCheck.Add("AttributeName", "NVARCHAR(255)"); |
2839 |
dicColCheck.Add("SppidSymbolName", "NVARCHAR(255)"); |
2840 |
if (matched == null) |
2841 |
{ |
2842 |
var query = $"CREATE TABLE {PSN_VALVEGROUP_SETTING} (OID NVARCHAR(50), GroupType NVARCHAR(255), TagIdentifier NVARCHAR(50), AttributeName NVARCHAR(255), SppidSymbolName NVARCHAR(255))"; |
2843 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2844 |
{ |
2845 |
cmd.ExecuteNonQuery(); |
2846 |
} |
2847 |
} |
2848 |
else |
2849 |
{ |
2850 |
AddColumn(PSN_VALVEGROUP_SETTING, dicColCheck); |
2851 |
} |
2852 |
|
2853 |
matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEM); |
2854 |
dicColCheck.Clear(); |
2855 |
dicColCheck.Add("OID", "NVARCHAR(255)"); |
2856 |
dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)"); |
2857 |
dicColCheck.Add("FLUID", "NVARCHAR(255)"); |
2858 |
dicColCheck.Add("PMC", "NVARCHAR(255)"); |
2859 |
dicColCheck.Add("PipeLineQty", "NVARCHAR(255)"); |
2860 |
dicColCheck.Add("GroundLevel", "NVARCHAR(20)"); |
2861 |
if (matched == null) |
2862 |
{ |
2863 |
var query = $"CREATE TABLE {PSN_PIPESYSTEM} (OID NVARCHAR(255), DESCRIPTION NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), PipeLineQty NVARCHAR(255), GroundLevel NVARCHAR(20))"; |
2864 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2865 |
{ |
2866 |
cmd.ExecuteNonQuery(); |
2867 |
} |
2868 |
} |
2869 |
else |
2870 |
{ |
2871 |
AddColumn(PSN_PIPESYSTEM, dicColCheck); |
2872 |
} |
2873 |
|
2874 |
matched = names.FirstOrDefault(param => param == PSN_NOPOCKETSETTING); |
2875 |
dicColCheck.Clear(); |
2876 |
dicColCheck.Add("[INDEX]", "INTEGER"); |
2877 |
dicColCheck.Add("[TYPE]", "TEXT"); |
2878 |
dicColCheck.Add("[NAME]", "TEXT"); |
2879 |
if (matched == null) |
2880 |
{ |
2881 |
var query = $"CREATE TABLE {PSN_NOPOCKETSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)"; |
2882 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2883 |
{ |
2884 |
cmd.ExecuteNonQuery(); |
2885 |
} |
2886 |
} |
2887 |
else |
2888 |
{ |
2889 |
AddColumn(PSN_NOPOCKETSETTING, dicColCheck); |
2890 |
} |
2891 |
|
2892 |
var query2 = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]"; |
2893 |
if (id2Info.ID2DBType == AnotherID2DB_Type.MSSQL) |
2894 |
{ |
2895 |
//connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
2896 |
using (var cmd = connection.GetSqlStringCommand(query2)) |
2897 |
{ |
2898 |
cmd.ExecuteNonQuery(); |
2899 |
} |
2900 |
} |
2901 |
|
2902 |
void AddColumn(string TableName, Dictionary<string, string> dicCol) |
2903 |
{ |
2904 |
var colnames = connection.GetColumnNames(TableName); |
2905 |
bool check = false; |
2906 |
if (colnames != null) |
2907 |
{ |
2908 |
foreach (KeyValuePair<string, string> col in dicCol) |
2909 |
{ |
2910 |
check = false; |
2911 |
foreach (string c in colnames) |
2912 |
{ |
2913 |
if (col.Key.ToUpper().Equals(c.ToUpper())) |
2914 |
{ |
2915 |
check = true; |
2916 |
break; |
2917 |
} |
2918 |
} |
2919 |
|
2920 |
if (!check) //없으면 추가 |
2921 |
{ |
2922 |
string i = string.Empty; |
2923 |
if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL")) |
2924 |
i = "DEFAULT 0"; |
2925 |
|
2926 |
var query = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";"; |
2927 |
using (var cmd = connection.GetSqlStringCommand(query)) |
2928 |
{ |
2929 |
cmd.ExecuteNonQuery(); |
2930 |
} |
2931 |
} |
2932 |
} |
2933 |
} |
2934 |
} |
2935 |
|
2936 |
result = true; |
2937 |
} |
2938 |
catch (Exception ex) |
2939 |
{ |
2940 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2941 |
} |
2942 |
} |
2943 |
|
2944 |
return result; |
2945 |
} |
2946 |
|
2947 |
public static bool SaveAnotherRevision(string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter, |
2948 |
int PidDrawings, int PipeSystems, int PipeLines, int Topologies, int PipeSystemNetworks, int InValidPSNs, int E2E, int E2B, int B2E, int HDE, int HD2, int HDB, int B2B) |
2949 |
{ |
2950 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
2951 |
|
2952 |
bool result = true; |
2953 |
|
2954 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
2955 |
{ |
2956 |
try |
2957 |
{ |
2958 |
using (var txn = connection.BeginTransaction()) |
2959 |
{ |
2960 |
try |
2961 |
{ |
2962 |
|
2963 |
var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " + |
2964 |
$"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " + |
2965 |
$"HD2, HDB, B2B, LastModificationdate) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" + |
2966 |
$", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " + |
2967 |
$"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate)"; |
2968 |
var cmd = connection.GetSqlStringCommand(query); |
2969 |
AddWithValue(cmd, "@OID", Guid.NewGuid().ToString()); |
2970 |
AddWithValue(cmd, "@Project_OID", Guid.NewGuid().ToString()); |
2971 |
AddWithValue(cmd, "@ProjectCode", ProjectCode); |
2972 |
AddWithValue(cmd, "@RevNumber", RevNumber); |
2973 |
AddWithValue(cmd, "@UserName", UserName); |
2974 |
|
2975 |
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US"); |
2976 |
DateTime oDateTime = DateTime.Now; |
2977 |
|
2978 |
AddWithValue(cmd, "@TimeData", oDateTime.ToString(ci)); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") |
2979 |
|
2980 |
AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath); |
2981 |
|
2982 |
AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter); |
2983 |
AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter); |
2984 |
AddWithValue(cmd, "@PidDrawings", PidDrawings); |
2985 |
AddWithValue(cmd, "@PipeSystems", PipeSystems); |
2986 |
AddWithValue(cmd, "@PipeLines", PipeLines); |
2987 |
|
2988 |
AddWithValue(cmd, "@Topologies", Topologies); |
2989 |
AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks); |
2990 |
AddWithValue(cmd, "@InValidPSNs", InValidPSNs); |
2991 |
AddWithValue(cmd, "@E2E", E2E); |
2992 |
AddWithValue(cmd, "@E2B", E2B); |
2993 |
AddWithValue(cmd, "@B2E", B2E); |
2994 |
AddWithValue(cmd, "@HDE", HDE); |
2995 |
AddWithValue(cmd, "@HD2", HD2); |
2996 |
AddWithValue(cmd, "@HDB", HDB); |
2997 |
AddWithValue(cmd, "@B2B", B2B); |
2998 |
|
2999 |
AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci)); |
3000 |
connection.ExecuteNonQuery(cmd, txn); |
3001 |
|
3002 |
txn.Commit(); |
3003 |
} |
3004 |
catch (Exception ex) |
3005 |
{ |
3006 |
txn.Rollback(); |
3007 |
result = false; |
3008 |
} |
3009 |
} |
3010 |
} |
3011 |
catch (Exception ex) |
3012 |
{ |
3013 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
3014 |
result = false; |
3015 |
} |
3016 |
} |
3017 |
|
3018 |
return result; |
3019 |
} |
3020 |
|
3021 |
public static bool ConnAnotherCreateRevisionTable(Dictionary<string, string> dicColCheck, List<string> names) |
3022 |
{ |
3023 |
bool result = false; |
3024 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
3025 |
|
3026 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
3027 |
{ |
3028 |
try |
3029 |
{ |
3030 |
if (names.Count == 0) |
3031 |
{ |
3032 |
|
3033 |
var query = $"CREATE TABLE ARS_COMMON.dbo.PSNRevision ([OID] [uniqueidentifier] ,[Project_OID] [uniqueidentifier] ," + |
3034 |
$"[ProjectCode] nvarchar(255), [RevNumber] int ,[UserName] nvarchar(255) ,[TimeData] nvarchar(255) ," + |
3035 |
$"[PSNDatabasePath] nvarchar(255) , [PsnByPBSFilter] varchar(20) ,[PsnByNPDFilter] varchar(20) ,[PidDrawings] int , " + |
3036 |
$"[PipeSystems] int ,[PipeLines] int ,[Topologies] int ,[PipeSystemNetworks] int ,[InValidPSNs] int ,[E2E] int ," + |
3037 |
$"[E2B] int ,[B2E] int ,[HDE] int ,[HD2] int ,[HDB] int ,[B2B] int , [LastModificationdate] nvarchar(255))"; |
3038 |
using (var cmd = connection.GetSqlStringCommand(query)) |
3039 |
{ |
3040 |
cmd.ExecuteNonQuery(); |
3041 |
} |
3042 |
} |
3043 |
else |
3044 |
{ |
3045 |
AddColumn(PSN_REVISION, dicColCheck, names); |
3046 |
} |
3047 |
|
3048 |
void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames) |
3049 |
{ |
3050 |
bool check = false; |
3051 |
if (colnames != null) |
3052 |
{ |
3053 |
foreach (KeyValuePair<string, string> col in dicCol) |
3054 |
{ |
3055 |
check = false; |
3056 |
foreach (string c in colnames) |
3057 |
{ |
3058 |
if (col.Key.Contains(c)) |
3059 |
{ |
3060 |
check = true; |
3061 |
break; |
3062 |
} |
3063 |
} |
3064 |
|
3065 |
if (!check) //없으면 추가 |
3066 |
{ |
3067 |
string i = string.Empty; |
3068 |
if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL")) |
3069 |
i = "DEFAULT 0"; |
3070 |
|
3071 |
var queryalter = $"ALTER TABLE ARS_COMMON.dbo.PSNRevision ADD [" + col.Key + "] " + col.Value + " " + i + ";"; |
3072 |
using (var cmd = connection.GetSqlStringCommand(queryalter)) |
3073 |
{ |
3074 |
cmd.ExecuteNonQuery(); |
3075 |
} |
3076 |
} |
3077 |
} |
3078 |
} |
3079 |
} |
3080 |
|
3081 |
result = true; |
3082 |
} |
3083 |
catch (Exception ex) |
3084 |
{ |
3085 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
3086 |
} |
3087 |
} |
3088 |
|
3089 |
return result; |
3090 |
} |
3091 |
|
3092 |
public static DataTable SelectAnotherRevision() |
3093 |
{ |
3094 |
DataTable dt = null; |
3095 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
3096 |
|
3097 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
3098 |
{ |
3099 |
try |
3100 |
{ |
3101 |
var query = $"SELECT * FROM ARS_COMMON.dbo.PSNREVISION"; |
3102 |
|
3103 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
3104 |
{ |
3105 |
dt = ds.Tables[0].Copy(); |
3106 |
} |
3107 |
} |
3108 |
catch (Exception ex) |
3109 |
{ |
3110 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
3111 |
} |
3112 |
} |
3113 |
|
3114 |
return dt; |
3115 |
} |
3116 |
|
3117 |
public static DataTable SelectAnotherRevisionTable() |
3118 |
{ |
3119 |
DataTable dt = null; |
3120 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
3121 |
|
3122 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
3123 |
{ |
3124 |
try |
3125 |
{ |
3126 |
var query = $"SELECT T.name AS table_name, C.name AS column_name FROM ARS_COMMON.sys.tables AS T INNER JOIN ARS_COMMON.sys.columns AS C ON T.object_id = C.object_id WHERE T.name = 'PSNREVISION'"; |
3127 |
using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query))) |
3128 |
{ |
3129 |
dt = ds.Tables[0].Copy(); |
3130 |
} |
3131 |
} |
3132 |
catch (Exception ex) |
3133 |
{ |
3134 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
3135 |
} |
3136 |
} |
3137 |
|
3138 |
return dt; |
3139 |
} |
3140 |
|
3141 |
public static bool SaveAnotherPSNData(PSN item, List<HeaderInfo> headerInfos, List<VentDrainInfo> ventDrainInfos, |
3142 |
List<KeywordItem> keywordItems, DataTable dtTopologyRule, DataTable dtFluidCode, DataTable dtPMC, DataTable dtInsulation, DataTable dtvalvegrouping, DataTable dtnopocket) |
3143 |
{ |
3144 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
3145 |
|
3146 |
bool result = true; |
3147 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
3148 |
{ |
3149 |
try |
3150 |
{ |
3151 |
using (var txn = connection.BeginTransaction()) |
3152 |
{ |
3153 |
try |
3154 |
{ |
3155 |
// Path Items |
3156 |
var query = $"DELETE FROM {PSN_PATHITEMS}"; |
3157 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3158 |
for (int i = 0; i < item.PathItems.Rows.Count; i++) |
3159 |
{ |
3160 |
DataRow row = item.PathItems.Rows[i]; |
3161 |
query = $"INSERT INTO {PSN_PATHITEMS} " + |
3162 |
$"(OID, SequenceData_OID, TopologySet_OID, BranchTopologySet_OID, PipeLine_OID, ItemName, ItemTag, DESCRIPTION, CLASS, SUBCLASS, TYPE, " + |
3163 |
$"PIDNAME, Equipment_OID, NPD, GROUPTAG, PipeSystemNetwork_OID, PipeRun_OID, ViewPipeSystemNetwork_OID) VALUES " + |
3164 |
$"(@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @DESCRIPTION, @Class, @SubClass, @TYPE, @PIDNAME," + |
3165 |
$" @Equipment_OID, @NPD, @GROUPTAG, @PipeSystemNetwork_OID,@PipeRun_OID, @ViewPipeSystemNetwork_OID)"; |
3166 |
var cmd = connection.GetSqlStringCommand(query); |
3167 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
3168 |
AddWithValue(cmd, "@SequenceData_OID", string.IsNullOrEmpty(row["SequenceData_OID"].ToString()) ? "" : row["SequenceData_OID"].ToString()); |
3169 |
AddWithValue(cmd, "@TopologySet_OID", string.IsNullOrEmpty(row["TopologySet_OID"].ToString()) ? "" : row["TopologySet_OID"].ToString()); |
3170 |
AddWithValue(cmd, "@BranchTopologySet_OID", string.IsNullOrEmpty(row["BranchTopologySet_OID"].ToString()) ? "" : row["BranchTopologySet_OID"].ToString()); |
3171 |
AddWithValue(cmd, "@PipeLine_OID", string.IsNullOrEmpty(row["PipeLine_OID"].ToString()) ? "" : row["PipeLine_OID"].ToString()); |
3172 |
AddWithValue(cmd, "@ITEMNAME", string.IsNullOrEmpty(row["ITEMNAME"].ToString()) ? "" : row["ITEMNAME"].ToString()); |
3173 |
AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString()); |
3174 |
AddWithValue(cmd, "@DESCRIPTION", string.IsNullOrEmpty(row["DESCRIPTION"].ToString()) ? "" : row["DESCRIPTION"].ToString()); |
3175 |
AddWithValue(cmd, "@Class", string.IsNullOrEmpty(row["Class"].ToString()) ? "" : row["Class"].ToString()); |
3176 |
AddWithValue(cmd, "@SubClass", string.IsNullOrEmpty(row["SubClass"].ToString()) ? "" : row["SubClass"].ToString()); |
3177 |
AddWithValue(cmd, "@TYPE", string.IsNullOrEmpty(row["TYPE"].ToString()) ? "" : row["TYPE"].ToString()); |
3178 |
AddWithValue(cmd, "@PIDNAME", string.IsNullOrEmpty(row["PIDNAME"].ToString()) ? "" : row["PIDNAME"].ToString()); |
3179 |
AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString()); |
3180 |
AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString()); |
3181 |
AddWithValue(cmd, "@GROUPTAG", string.IsNullOrEmpty(row["GROUPTAG"].ToString()) ? "" : row["GROUPTAG"].ToString()); |
3182 |
AddWithValue(cmd, "@PipeSystemNetwork_OID", string.IsNullOrEmpty(row["PipeSystemNetwork_OID"].ToString()) ? "" : row["PipeSystemNetwork_OID"].ToString()); |
3183 |
AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", string.IsNullOrEmpty(row["ViewPipeSystemNetwork_OID"].ToString()) ? "" : row["ViewPipeSystemNetwork_OID"].ToString()); |
3184 |
AddWithValue(cmd, "@PipeRun_OID", string.IsNullOrEmpty(row["PipeRun_OID"].ToString()) ? "" : row["PipeRun_OID"].ToString()); |
3185 |
connection.ExecuteNonQuery(cmd, txn); |
3186 |
} |
3187 |
|
3188 |
// Sequence |
3189 |
query = $"DELETE FROM {PSN_SEQUENCEDATA}"; |
3190 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3191 |
foreach (DataRow row in item.SequenceData.Rows) |
3192 |
{ |
3193 |
query = $"INSERT INTO {PSN_SEQUENCEDATA} (OID, SERIALNUMBER, PathItem_OID, TopologySet_OID_Key) VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)"; |
3194 |
var cmd = connection.GetSqlStringCommand(query); |
3195 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
3196 |
AddWithValue(cmd, "@SERIALNUMBER", string.IsNullOrEmpty(row["SERIALNUMBER"].ToString()) ? "" : row["SERIALNUMBER"].ToString()); |
3197 |
AddWithValue(cmd, "@PathItem_OID", string.IsNullOrEmpty(row["PathItem_OID"].ToString()) ? "" : row["PathItem_OID"].ToString()); |
3198 |
AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString()); |
3199 |
connection.ExecuteNonQuery(cmd, txn); |
3200 |
} |
3201 |
|
3202 |
// Nozzle |
3203 |
query = $"DELETE FROM {PSN_NOZZLE}"; |
3204 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3205 |
foreach (DataRow row in item.Nozzle.Rows) |
3206 |
{ |
3207 |
query = $"INSERT INTO {PSN_NOZZLE} (OID, ItemTag, Xcoords, Ycoords, Equipment_OID, Fluid, NPD, PMC, Rotation, FlowDirection) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @PMC, @ROTATION, @FlowDirection)"; |
3208 |
var cmd = connection.GetSqlStringCommand(query); |
3209 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
3210 |
AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString()); |
3211 |
|
3212 |
if (string.IsNullOrEmpty(row["XCOORDS"].ToString())) |
3213 |
AddWithValue(cmd, "@XCOORDS", DBNull.Value); |
3214 |
else |
3215 |
AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString()); |
3216 |
|
3217 |
if (string.IsNullOrEmpty(row["YCOORDS"].ToString())) |
3218 |
AddWithValue(cmd, "@YCOORDS", DBNull.Value); |
3219 |
else |
3220 |
AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString()); |
3221 |
|
3222 |
AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString()); |
3223 |
AddWithValue(cmd, "@FLUID", string.IsNullOrEmpty(row["FLUID"].ToString()) ? "" : row["FLUID"].ToString()); |
3224 |
AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString()); |
3225 |
AddWithValue(cmd, "@PMC", string.IsNullOrEmpty(row["PMC"].ToString()) ? "" : row["PMC"].ToString()); |
3226 |
|
3227 |
if (string.IsNullOrEmpty(row["ROTATION"].ToString())) |
3228 |
AddWithValue(cmd, "@ROTATION", DBNull.Value); |
3229 |
else |
3230 |
AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString()); |
3231 |
|
3232 |
AddWithValue(cmd, "@FlowDirection", string.IsNullOrEmpty(row["FlowDirection"].ToString()) ? "" : row["FlowDirection"].ToString()); |
3233 |
connection.ExecuteNonQuery(cmd, txn); |
3234 |
} |
3235 |
|
3236 |
//Equipment |
3237 |
query = $"DELETE FROM {PSN_EQUIPMENT}"; |
3238 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3239 |
foreach (DataRow row in item.Equipment.Rows) |
3240 |
{ |
3241 |
query = $"INSERT INTO {PSN_EQUIPMENT} (OID, ItemTag, Xcoords, Ycoords) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)"; |
3242 |
var cmd = connection.GetSqlStringCommand(query); |
3243 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
3244 |
AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString()); |
3245 |
|
3246 |
if (string.IsNullOrEmpty(row["XCOORDS"].ToString())) |
3247 |
AddWithValue(cmd, "@XCOORDS", DBNull.Value); |
3248 |
else |
3249 |
AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString()); |
3250 |
|
3251 |
if (string.IsNullOrEmpty(row["YCOORDS"].ToString())) |
3252 |
AddWithValue(cmd, "@YCOORDS", DBNull.Value); |
3253 |
else |
3254 |
AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString()); |
3255 |
|
3256 |
connection.ExecuteNonQuery(cmd, txn); |
3257 |
} |
3258 |
|
3259 |
// TopologySet |
3260 |
query = $"DELETE FROM {PSN_TOPOLOGYSET}"; |
3261 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3262 |
foreach (DataRow row in item.TopologySet.Rows) |
3263 |
{ |
3264 |
query = $"INSERT INTO {PSN_TOPOLOGYSET} (OID, Type, SubType, HeadItemTag, TailItemTag, HeadItemSPID, TailItemSPID) VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemSPID, @TailItemSPID)"; |
3265 |
var cmd = connection.GetSqlStringCommand(query); |
3266 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
3267 |
AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString()); |
3268 |
AddWithValue(cmd, "@SubType", string.IsNullOrEmpty(row["SubType"].ToString()) ? "" : row["SubType"].ToString()); |
3269 |
AddWithValue(cmd, "@HeadItemTag", string.IsNullOrEmpty(row["HeadItemTag"].ToString()) ? "" : row["HeadItemTag"].ToString()); |
3270 |
AddWithValue(cmd, "@TailItemTag", string.IsNullOrEmpty(row["TailItemTag"].ToString()) ? "" : row["TailItemTag"].ToString()); |
3271 |
AddWithValue(cmd, "@HeadItemSPID", string.IsNullOrEmpty(row["HeadItemSPID"].ToString()) ? "" : row["HeadItemSPID"].ToString()); |
3272 |
AddWithValue(cmd, "@TailItemSPID", string.IsNullOrEmpty(row["TailItemSPID"].ToString()) ? "" : row["TailItemSPID"].ToString()); |
3273 |
connection.ExecuteNonQuery(cmd, txn); |
3274 |
} |
3275 |
|
3276 |
// PSN |
3277 |
query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'"; |
3278 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3279 |
foreach (DataRow row in item.PipeSystemNetwork.Rows) |
3280 |
{ |
3281 |
query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} " + |
3282 |
$"(OID, Type, OrderNumber, Pipeline_OID, FROM_DATA, TO_DATA, TopologySet_OID_Key, PSNRevisionNumber, PBS, Drawings, IsValid, Status, IncludingVirtualData, PSNAccuracy) VALUES " + |
3283 |
$"(@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber, @PBS, @Drawings, @IsValid, @Status, @IncludingVirtualData, @PSNAccuracy)"; |
3284 |
var cmd = connection.GetSqlStringCommand(query); |
3285 |
AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString()); |
3286 |
AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString()); |
3287 |
AddWithValue(cmd, "@OrderNumber", string.IsNullOrEmpty(row["OrderNumber"].ToString()) ? "" : row["OrderNumber"].ToString()); |
3288 |
AddWithValue(cmd, "@Pipeline_OID", string.IsNullOrEmpty(row["Pipeline_OID"].ToString()) ? "" : row["Pipeline_OID"].ToString()); |
3289 |
AddWithValue(cmd, "@FROM_DATA", string.IsNullOrEmpty(row["FROM_DATA"].ToString()) ? "" : row["FROM_DATA"].ToString()); |
3290 |
AddWithValue(cmd, "@TO_DATA", string.IsNullOrEmpty(row["TO_DATA"].ToString()) ? "" : row["TO_DATA"].ToString()); |
3291 |
AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString()); |
3292 |
AddWithValue(cmd, "@PSNRevisionNumber", string.IsNullOrEmpty(row["PSNRevisionNumber"].ToString()) ? "" : row["PSNRevisionNumber"].ToString()); |
3293 |
|
3294 |
int IsValid = 0; |
3295 |
if (row["IsValid"].ToString() == string.Empty || row["IsValid"].ToString() == "OK") |
3296 |
IsValid = 0; |
3297 |
else if (row["IsValid"].ToString() == "InValid") |
3298 |
IsValid = 1; |
3299 |
else if (row["IsValid"].ToString() == "Error") |
3300 |
IsValid = -1; |
3301 |
|
3302 |
AddWithValue(cmd, "@IsValid", IsValid); |
3303 |
AddWithValue(cmd, "@Status", string.IsNullOrEmpty(row["Status"].ToString()) ? "" : row["Status"].ToString()); |
3304 |
|
3305 |
AddWithValue(cmd, "@PBS", string.IsNullOrEmpty(row["PBS"].ToString()) ? "" : row["PBS"].ToString()); |
3306 |
AddWithValue(cmd, "@Drawings", string.IsNullOrEmpty(row["Drawings"].ToString()) ? "" : row["Drawings"].ToString()); |
3307 |
|
3308 |
AddWithValue(cmd, "@IncludingVirtualData", string.IsNullOrEmpty(row["IncludingVirtualData"].ToString()) ? "" : row["IncludingVirtualData"].ToString()); |
3309 |
if (string.IsNullOrEmpty(row["PSNAccuracy"].ToString())) |
3310 |
AddWithValue(cmd, "@PSNAccuracy", DBNull.Value); |
3311 |
else |
3312 |
AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString()); |
3313 |
|
3314 |
connection.ExecuteNonQuery(cmd, txn); |
3315 |
} |
3316 |
|
3317 |
//Pipeline |
3318 |
query = $"DELETE FROM {PSN_PIPELINE}"; |
3319 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3320 |
foreach (DataRow row in item.PipeLine.Rows) |
3321 |
{ |
3322 |
query = $"INSERT INTO {PSN_PIPELINE} (OID, PipeSystem_OID, FLUID, PMC, SEQNUMBER, INSULATION, FROM_DATA, TO_DATA, Unit) VALUES (@OID, @PipeSystem_OID, @FLUID, @PMC, @SEQNUMBER, @INSULATION, @FROM_DATA, @TO_DATA, @Unit)"; |
3323 |
var cmd = connection.GetSqlStringCommand(query); |
3324 |
AddWithValue(cmd, "@OID", row["OID"].ToString()); |
3325 |
AddWithValue(cmd, "@PipeSystem_OID", row["PipeSystem_OID"].ToString()); |
3326 |
AddWithValue(cmd, "@FLUID", row["FLUID"].ToString()); |
3327 |
AddWithValue(cmd, "@PMC", row["PMC"].ToString()); |
3328 |
AddWithValue(cmd, "@SEQNUMBER", row["SEQNUMBER"].ToString()); |
3329 |
AddWithValue(cmd, "@INSULATION", row["INSULATION"].ToString()); |
3330 |
AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString()); |
3331 |
AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString()); |
3332 |
AddWithValue(cmd, "@Unit", row["Unit"].ToString()); |
3333 |
connection.ExecuteNonQuery(cmd, txn); |
3334 |
} |
3335 |
|
3336 |
//PipeSystem |
3337 |
query = $"DELETE FROM {PSN_PIPESYSTEM}"; |
3338 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3339 |
foreach (DataRow row in item.PipeSystem.Rows) |
3340 |
{ |
3341 |
query = $"INSERT INTO {PSN_PIPESYSTEM} (OID, DESCRIPTION, FLUID, PMC, PipeLineQty, GroundLevel) VALUES (@OID, @DESCRIPTION, @FLUID, @PMC, @PipeLineQty, @GroundLevel)"; |
3342 |
var cmd = connection.GetSqlStringCommand(query); |
3343 |
AddWithValue(cmd, "@OID", row["OID"].ToString()); |
3344 |
AddWithValue(cmd, "@DESCRIPTION", row["DESCRIPTION"].ToString()); |
3345 |
AddWithValue(cmd, "@FLUID", row["FLUID"].ToString()); |
3346 |
AddWithValue(cmd, "@PMC", row["PMC"].ToString()); |
3347 |
AddWithValue(cmd, "@PipeLineQty", row["PipeLineQty"].ToString()); |
3348 |
AddWithValue(cmd, "@GroundLevel", row["GroundLevel"].ToString()); |
3349 |
connection.ExecuteNonQuery(cmd, txn); |
3350 |
} |
3351 |
|
3352 |
//Header Setting |
3353 |
query = $"DELETE FROM {PSN_HEADER_SETTING}"; |
3354 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3355 |
|
3356 |
foreach (HeaderInfo headerInfo in headerInfos) |
3357 |
{ |
3358 |
foreach (HeaderItem itemheader in headerInfo.HeaderItems) |
3359 |
{ |
3360 |
query = $"INSERT INTO {PSN_HEADER_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)"; |
3361 |
var cmd = connection.GetSqlStringCommand(query); |
3362 |
AddWithValue(cmd, "@GROUP_ID", headerInfo.UID); |
3363 |
AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description); |
3364 |
AddWithValue(cmd, "@INDEX", itemheader.Index); |
3365 |
AddWithValue(cmd, "@NAME", itemheader.Name); |
3366 |
connection.ExecuteNonQuery(cmd, txn); |
3367 |
} |
3368 |
} |
3369 |
|
3370 |
//Vent/Drain Setting |
3371 |
query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}"; |
3372 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3373 |
|
3374 |
foreach (VentDrainInfo ventDrainInfo in ventDrainInfos) |
3375 |
{ |
3376 |
foreach (VentDrainItem itemventdrain in ventDrainInfo.VentDrainItems) |
3377 |
{ |
3378 |
query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)"; |
3379 |
var cmd = connection.GetSqlStringCommand(query); |
3380 |
AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID); |
3381 |
AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description); |
3382 |
AddWithValue(cmd, "@INDEX", itemventdrain.Index); |
3383 |
AddWithValue(cmd, "@NAME", itemventdrain.Name); |
3384 |
connection.ExecuteNonQuery(cmd, txn); |
3385 |
} |
3386 |
} |
3387 |
|
3388 |
//Keyword Setting |
3389 |
query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}"; |
3390 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3391 |
|
3392 |
foreach (KeywordItem itemKeyword in keywordItems) |
3393 |
{ |
3394 |
query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX], NAME, KEYWORD) VALUES (@INDEX, @NAME, @KEYWORD)"; |
3395 |
var cmd = connection.GetSqlStringCommand(query); |
3396 |
AddWithValue(cmd, "@INDEX", itemKeyword.Index); |
3397 |
AddWithValue(cmd, "@NAME", itemKeyword.Name); |
3398 |
AddWithValue(cmd, "@KEYWORD", itemKeyword.Keyword); |
3399 |
connection.ExecuteNonQuery(cmd, txn); |
3400 |
} |
3401 |
|
3402 |
//FulidCode |
3403 |
query = $"DELETE FROM {PSN_FLUIDCODE}"; |
3404 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3405 |
|
3406 |
foreach (DataRow row in dtFluidCode.Rows) |
3407 |
{ |
3408 |
query = $"INSERT INTO {PSN_FLUIDCODE} (UID, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)"; |
3409 |
var cmd = connection.GetSqlStringCommand(query); |
3410 |
cmd.Parameters.Clear(); |
3411 |
|
3412 |
{ |
3413 |
var param = cmd.CreateParameter(); |
3414 |
param.ParameterName = "@UID"; |
3415 |
param.Value = row["UID"].ToString(); |
3416 |
cmd.Parameters.Add(param); |
3417 |
} |
3418 |
|
3419 |
{ |
3420 |
var param = cmd.CreateParameter(); |
3421 |
param.ParameterName = "@Code"; |
3422 |
param.Value = row["Code"].ToString(); |
3423 |
cmd.Parameters.Add(param); |
3424 |
} |
3425 |
|
3426 |
{ |
3427 |
var param = cmd.CreateParameter(); |
3428 |
param.ParameterName = "@Description"; |
3429 |
param.Value = row["Description"].ToString(); |
3430 |
cmd.Parameters.Add(param); |
3431 |
} |
3432 |
|
3433 |
{ |
3434 |
var param = cmd.CreateParameter(); |
3435 |
param.ParameterName = "@Condition"; |
3436 |
param.Value = row["Condition"].ToString(); |
3437 |
cmd.Parameters.Add(param); |
3438 |
} |
3439 |
|
3440 |
{ |
3441 |
var param = cmd.CreateParameter(); |
3442 |
param.ParameterName = "@Remarks"; |
3443 |
param.Value = row["Remarks"].ToString(); |
3444 |
cmd.Parameters.Add(param); |
3445 |
} |
3446 |
|
3447 |
{ |
3448 |
var param = cmd.CreateParameter(); |
3449 |
param.ParameterName = "@GroundLevel"; |
3450 |
param.Value = row["GroundLevel"].ToString(); |
3451 |
cmd.Parameters.Add(param); |
3452 |
} |
3453 |
|
3454 |
connection.ExecuteNonQuery(cmd, txn); |
3455 |
} |
3456 |
|
3457 |
//PMC |
3458 |
query = $"DELETE FROM {PSN_PIPINGMATLCLASS}"; |
3459 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3460 |
|
3461 |
foreach (DataRow row in dtPMC.Rows) |
3462 |
{ |
3463 |
query = $"INSERT INTO {PSN_PIPINGMATLCLASS} ( UID, Priority, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)"; |
3464 |
var cmd = connection.GetSqlStringCommand(query); |
3465 |
cmd.Parameters.Clear(); |
3466 |
|
3467 |
{ |
3468 |
var param = cmd.CreateParameter(); |
3469 |
param.ParameterName = "@UID"; |
3470 |
param.Value = row["UID"].ToString(); |
3471 |
cmd.Parameters.Add(param); |
3472 |
} |
3473 |
|
3474 |
{ |
3475 |
var param = cmd.CreateParameter(); |
3476 |
param.ParameterName = "@Priority"; |
3477 |
param.Value = row["Priority"].ToString(); |
3478 |
cmd.Parameters.Add(param); |
3479 |
} |
3480 |
|
3481 |
{ |
3482 |
var param = cmd.CreateParameter(); |
3483 |
param.ParameterName = "@Code"; |
3484 |
param.Value = row["Code"].ToString(); |
3485 |
cmd.Parameters.Add(param); |
3486 |
} |
3487 |
|
3488 |
{ |
3489 |
var param = cmd.CreateParameter(); |
3490 |
param.ParameterName = "@Description"; |
3491 |
param.Value = row["Description"].ToString(); |
3492 |
cmd.Parameters.Add(param); |
3493 |
} |
3494 |
|
3495 |
{ |
3496 |
var param = cmd.CreateParameter(); |
3497 |
param.ParameterName = "@Condition"; |
3498 |
param.Value = row["Condition"].ToString(); |
3499 |
cmd.Parameters.Add(param); |
3500 |
} |
3501 |
|
3502 |
{ |
3503 |
var param = cmd.CreateParameter(); |
3504 |
param.ParameterName = "@Remarks"; |
3505 |
param.Value = row["Remarks"].ToString(); |
3506 |
cmd.Parameters.Add(param); |
3507 |
} |
3508 |
|
3509 |
{ |
3510 |
var param = cmd.CreateParameter(); |
3511 |
param.ParameterName = "@GroundLevel"; |
3512 |
param.Value = row["GroundLevel"].ToString(); |
3513 |
cmd.Parameters.Add(param); |
3514 |
} |
3515 |
|
3516 |
connection.ExecuteNonQuery(cmd, txn); |
3517 |
} |
3518 |
|
3519 |
//Insulation |
3520 |
query = $"DELETE FROM {PSN_INSULATIONPURPOSE}"; |
3521 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3522 |
|
3523 |
foreach (DataRow row in dtInsulation.Rows) |
3524 |
{ |
3525 |
query = $"INSERT INTO {PSN_INSULATIONPURPOSE} (UID, Code, Description, Remarks) VALUES (@UID, @Code, @Description, @Remarks)"; |
3526 |
var cmd = connection.GetSqlStringCommand(query); |
3527 |
cmd.Parameters.Clear(); |
3528 |
|
3529 |
{ |
3530 |
var param = cmd.CreateParameter(); |
3531 |
param.ParameterName = "@UID"; |
3532 |
param.Value = row["UID"].ToString(); |
3533 |
cmd.Parameters.Add(param); |
3534 |
} |
3535 |
|
3536 |
{ |
3537 |
var param = cmd.CreateParameter(); |
3538 |
param.ParameterName = "@Code"; |
3539 |
param.Value = row["Code"].ToString(); |
3540 |
cmd.Parameters.Add(param); |
3541 |
} |
3542 |
|
3543 |
{ |
3544 |
var param = cmd.CreateParameter(); |
3545 |
param.ParameterName = "@Description"; |
3546 |
param.Value = row["Description"].ToString(); |
3547 |
cmd.Parameters.Add(param); |
3548 |
} |
3549 |
|
3550 |
{ |
3551 |
var param = cmd.CreateParameter(); |
3552 |
param.ParameterName = "@Remarks"; |
3553 |
param.Value = row["Remarks"].ToString(); |
3554 |
cmd.Parameters.Add(param); |
3555 |
} |
3556 |
|
3557 |
connection.ExecuteNonQuery(cmd, txn); |
3558 |
} |
3559 |
|
3560 |
//Topology Rule |
3561 |
query = $"DELETE FROM {PSN_TOPOLOGY_RULE}"; |
3562 |
var cmdtopology = connection.GetSqlStringCommand(query); |
3563 |
//connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3564 |
connection.ExecuteNonQuery(cmdtopology, txn); |
3565 |
|
3566 |
foreach (DataRow row in dtTopologyRule.Rows) |
3567 |
{ |
3568 |
query = $"INSERT INTO {PSN_TOPOLOGY_RULE} (UID) VALUES (@UID)"; |
3569 |
cmdtopology = connection.GetSqlStringCommand(query); |
3570 |
AddWithValue(cmdtopology, "@UID", row["UID"].ToString()); |
3571 |
connection.ExecuteNonQuery(cmdtopology, txn); |
3572 |
} |
3573 |
|
3574 |
//valve grouping |
3575 |
query = $"DELETE FROM {PSN_VALVEGROUP_SETTING}"; |
3576 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3577 |
|
3578 |
foreach (DataRow row in dtvalvegrouping.Rows) |
3579 |
{ |
3580 |
query = $"INSERT INTO {PSN_VALVEGROUP_SETTING} (OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName) " + |
3581 |
$"VALUES (@OID, @GroupType, @TagIdentifier, @AttributeName, @SppidSymbolName)"; |
3582 |
var cmd = connection.GetSqlStringCommand(query); |
3583 |
AddWithValue(cmd, "@OID", row["OID"].ToString()); |
3584 |
AddWithValue(cmd, "@GroupType", row["GroupType"].ToString()); |
3585 |
AddWithValue(cmd, "@TagIdentifier", row["TagIdentifier"].ToString()); |
3586 |
AddWithValue(cmd, "@AttributeName", row["AttributeName"].ToString()); |
3587 |
AddWithValue(cmd, "@SppidSymbolName", row["SppidSymbolName"].ToString()); |
3588 |
connection.ExecuteNonQuery(cmd, txn); |
3589 |
} |
3590 |
|
3591 |
//no pocket Setting |
3592 |
query = $"DELETE FROM {PSN_NOPOCKETSETTING}"; |
3593 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3594 |
|
3595 |
foreach (DataRow row in dtnopocket.Rows) |
3596 |
{ |
3597 |
query = $"INSERT INTO {PSN_NOPOCKETSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)"; |
3598 |
var cmd = connection.GetSqlStringCommand(query); |
3599 |
AddWithValue(cmd, "@INDEX", row["INDEX"].ToString()); |
3600 |
AddWithValue(cmd, "@TYPE", row["TYPE"].ToString()); |
3601 |
AddWithValue(cmd, "@NAME", row["NAME"].ToString()); |
3602 |
connection.ExecuteNonQuery(cmd, txn); |
3603 |
} |
3604 |
|
3605 |
txn.Commit(); |
3606 |
} |
3607 |
catch (Exception ex) |
3608 |
{ |
3609 |
txn.Rollback(); |
3610 |
result = false; |
3611 |
} |
3612 |
} |
3613 |
} |
3614 |
catch (Exception ex) |
3615 |
{ |
3616 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
3617 |
result = false; |
3618 |
} |
3619 |
} |
3620 |
|
3621 |
return result; |
3622 |
} |
3623 |
|
3624 |
public static bool CreatePSN_COMMON() |
3625 |
{ |
3626 |
AnotherID2Info id2Info = AnotherID2Info.GetInstance(); |
3627 |
|
3628 |
bool result = true; |
3629 |
using (IAbstractDatabase connection = id2Info.CreateConnection()) |
3630 |
{ |
3631 |
try |
3632 |
{ |
3633 |
using (var txn = connection.BeginTransaction()) |
3634 |
{ |
3635 |
try |
3636 |
{ |
3637 |
|
3638 |
var query = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]"; |
3639 |
if (id2Info.ID2DBType == AnotherID2DB_Type.MSSQL) |
3640 |
{ |
3641 |
connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn); |
3642 |
} |
3643 |
|
3644 |
txn.Commit(); |
3645 |
} |
3646 |
catch (Exception ex) |
3647 |
{ |
3648 |
txn.Rollback(); |
3649 |
result = false; |
3650 |
} |
3651 |
} |
3652 |
} |
3653 |
catch (Exception ex) |
3654 |
{ |
3655 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
3656 |
result = false; |
3657 |
} |
3658 |
} |
3659 |
|
3660 |
return result; |
3661 |
} |
3662 |
} |
3663 |
} |
3664 |
|
3665 |
|