개정판 c8da68ce
dev issue #1227 : Save symbol mapping
Change-Id: Ied99ec5ec5b9c36e3d03b0aa668c4e4688492f03
DTI_PID/APIDConverter/DB/Project_DB.cs | ||
---|---|---|
398 | 398 |
|
399 | 399 |
return dt; |
400 | 400 |
} |
401 |
public static bool InsertSymbolMapping(List<Tuple<string, string, string>> datas) |
|
402 |
{ |
|
403 |
Project_Info projectInfo = Project_Info.GetInstance(); |
|
404 |
if (projectInfo.DBType == ID2DB_Type.SQLite) |
|
405 |
{ |
|
406 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
|
407 |
{ |
|
408 |
try |
|
409 |
{ |
|
410 |
connection.Open(); |
|
411 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
412 |
{ |
|
413 |
try |
|
414 |
{ |
|
415 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
416 |
{ |
|
417 |
foreach (var item in datas) |
|
418 |
{ |
|
419 |
cmd.Parameters.Clear(); |
|
420 |
cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, APID_SYMBOL) VALUES (@UID, @NAME, @APID_SYMBOL)", APID_SYMBOL_MAPPING_TABLE); |
|
421 |
cmd.Parameters.AddWithValue("@UID", item.Item1); |
|
422 |
cmd.Parameters.AddWithValue("@NAME", item.Item2); |
|
423 |
cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3); |
|
424 |
cmd.ExecuteNonQuery(); |
|
425 |
} |
|
426 |
} |
|
427 |
transaction.Commit(); |
|
428 |
connection.Close(); |
|
429 |
} |
|
430 |
catch (Exception ex) |
|
431 |
{ |
|
432 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
433 |
transaction.Rollback(); |
|
434 |
return false; |
|
435 |
} |
|
436 |
finally |
|
437 |
{ |
|
438 |
transaction.Dispose(); |
|
439 |
} |
|
440 |
} |
|
441 |
} |
|
442 |
catch (Exception ex) |
|
443 |
{ |
|
444 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
445 |
return false; |
|
446 |
} |
|
447 |
finally |
|
448 |
{ |
|
449 |
connection.Dispose(); |
|
450 |
} |
|
451 |
} |
|
452 |
} |
|
453 |
else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
|
454 |
{ |
|
455 |
using (SqlConnection connection = GetSqlConnection()) |
|
456 |
{ |
|
457 |
try |
|
458 |
{ |
|
459 |
if (connection != null && connection.State == ConnectionState.Open) |
|
460 |
{ |
|
461 |
using (SqlCommand cmd = connection.CreateCommand()) |
|
462 |
{ |
|
463 |
foreach (var item in datas) |
|
464 |
{ |
|
465 |
cmd.Parameters.Clear(); |
|
466 |
cmd.CommandText = string.Format(@" |
|
467 |
IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
|
468 |
UPDATE {0} SET NAME = @NAME, APID_SYMBOL = @APID_SYMBOL WHERE UID = @UID |
|
469 |
ELSE |
|
470 |
INSERT INTO {0} (UID, NAME, APID_SYMBOL) VALUES (@UID, @NAME, @APID_SYMBOL)", APID_SYMBOL_MAPPING_TABLE, item.Item1); |
|
471 |
cmd.Parameters.AddWithValue("@UID", item.Item1); |
|
472 |
if (string.IsNullOrEmpty(item.Item2)) |
|
473 |
cmd.Parameters.AddWithValue("@NAME", DBNull.Value); |
|
474 |
else |
|
475 |
cmd.Parameters.AddWithValue("@NAME", item.Item2); |
|
476 |
if (string.IsNullOrEmpty(item.Item3)) |
|
477 |
cmd.Parameters.AddWithValue("@APID_SYMBOL", DBNull.Value); |
|
478 |
else |
|
479 |
cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3); |
|
480 |
cmd.ExecuteNonQuery(); |
|
481 |
} |
|
482 |
} |
|
483 |
connection.Close(); |
|
484 |
} |
|
485 |
} |
|
486 |
catch (Exception ex) |
|
487 |
{ |
|
488 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
489 |
return false; |
|
490 |
} |
|
491 |
finally |
|
492 |
{ |
|
493 |
if (connection != null) |
|
494 |
connection.Dispose(); |
|
495 |
} |
|
496 |
} |
|
497 |
} |
|
498 |
|
|
499 |
return true; |
|
500 |
} |
|
401 | 501 |
#endregion |
402 | 502 |
|
403 | 503 |
#region AVEVA |
내보내기 Unified diff