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