개정판 6b60e542
Add Function RunUpdatePipeRunProperties
Change-Id: I02a4e7cf345312732d677381c77d2d2e9145ac1d
DTI_PID/SPPIDConverter/DB/Project_DB.cs | ||
---|---|---|
11 | 11 |
using System.IO; |
12 | 12 |
using Newtonsoft.Json; |
13 | 13 |
using Converter.SPPID.Model; |
14 |
using Converter.SPPID.DB; |
|
14 | 15 |
|
15 | 16 |
namespace Converter.BaseModel |
16 | 17 |
{ |
... | ... | |
23 | 24 |
const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO"; |
24 | 25 |
const string SPPID_DRAWING_INFO = "T_SPPID_DRAWING_INFO"; |
25 | 26 |
const string SPPID_OPC_INFO = "T_SPPID_OPC_INFO"; |
27 |
const string SPPID_PIPERUN_PROP_SETTING = "T_SPPID_PIPERUN_PROP_SETTING"; |
|
26 | 28 |
const string ID2_DRAWINGATTRIBUTE_TABLE = "T_ID2_DRAWINGATTRIBUTE"; |
27 | 29 |
const string ID2_NOMINALDIAMETER_TABLE = "NominalDiameter"; |
28 | 30 |
|
... | ... | |
117 | 119 |
cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID TEXT PRIMARY KEY, SPPID_OPC_MODELITEM_ID TEXT, ID2_DRAWING_UID TEXT, ATTRIBUTES TEXT, PAIRED BOOL)", SPPID_OPC_INFO); |
118 | 120 |
cmd.ExecuteNonQuery(); |
119 | 121 |
} |
122 |
if (dt.Select(string.Format("NAME = '{0}'", SPPID_PIPERUN_PROP_SETTING)).Length == 0) |
|
123 |
{ |
|
124 |
cmd.CommandText = string.Format(@"CREATE TABLE {0} (UID TEXT NOT NULL PRIMARY KEY, |
|
125 |
ShowType int NOT NULL,Name TEXT NOT NULL,DisplayName TEXT NOT NULL,TableName TEXT NOT NULL,DataType TEXT NOT NULL,Value TEXT NOT NULL, |
|
126 |
Cond1_Name TEXT NOT NULL,Cond1_DisplayName TEXT NOT NULL,Cond1_TableName TEXT NOT NULL,Cond1_DataType TEXT NOT NULL,Cond1_Value TEXT NOT NULL, |
|
127 |
Cond2_Name TEXT,Cond2_DisplayName TEXT,Cond2_TableName TEXT,Cond2_DataType TEXT,Cond2_Value TEXT,SortOrder int NOT NULL)", SPPID_PIPERUN_PROP_SETTING); |
|
128 |
cmd.ExecuteNonQuery(); |
|
129 |
} |
|
120 | 130 |
if (dt.Select(string.Format("NAME = '{0}'", ID2_DRAWINGATTRIBUTE_TABLE)).Length == 0) |
121 | 131 |
{ |
122 | 132 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT)", ID2_DRAWINGATTRIBUTE_TABLE); |
... | ... | |
249 | 259 |
cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID varchar(255) PRIMARY KEY, SPPID_OPC_MODELITEM_ID varchar(MAX), ID2_DRAWING_UID varchar(MAX), ATTRIBUTES varchar(MAX), PAIRED BIT)", SPPID_OPC_INFO); |
250 | 260 |
cmd.ExecuteNonQuery(); |
251 | 261 |
} |
262 |
if (dt.Select(string.Format("NAME = '{0}'", SPPID_PIPERUN_PROP_SETTING)).Length == 0) |
|
263 |
{ |
|
264 |
cmd.CommandText = string.Format(@"CREATE TABLE {0} (UID nvarchar(36) NOT NULL PRIMARY KEY, |
|
265 |
ShowType int NOT NULL,Name nvarchar(255) NOT NULL,DisplayName nvarchar(255) NOT NULL,TableName nvarchar(255) NOT NULL,DataType nvarchar(6) NOT NULL,Value nvarchar(255) NOT NULL, |
|
266 |
Cond1_Name nvarchar(255) NOT NULL,Cond1_DisplayName nvarchar(255) NOT NULL,Cond1_TableName nvarchar(255) NOT NULL,Cond1_DataType nvarchar(6) NOT NULL,Cond1_Value nvarchar(255) NOT NULL, |
|
267 |
Cond2_Name nvarchar(255),Cond2_DisplayName nvarchar(255),Cond2_TableName nvarchar(255),Cond2_DataType nvarchar(6),Cond2_Value nvarchar(255),SortOrder int NOT NULL)", SPPID_PIPERUN_PROP_SETTING); |
|
268 |
cmd.ExecuteNonQuery(); |
|
269 |
} |
|
252 | 270 |
if (dt.Select(string.Format("NAME = '{0}'", ID2_DRAWINGATTRIBUTE_TABLE)).Length == 0) |
253 | 271 |
{ |
254 | 272 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(255))", ID2_DRAWINGATTRIBUTE_TABLE); |
... | ... | |
510 | 528 |
|
511 | 529 |
return true; |
512 | 530 |
} |
531 |
public static bool SavePipeRunPropSetting(List<SPPID_PipeRunPropSetting> setting) |
|
532 |
{ |
|
533 |
Project_Info projectInfo = Project_Info.GetInstance(); |
|
534 |
if (projectInfo.DBType == ID2DB_Type.SQLite) |
|
535 |
{ |
|
536 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true)) |
|
537 |
{ |
|
538 |
try |
|
539 |
{ |
|
540 |
connection.Open(); |
|
541 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
542 |
{ |
|
543 |
cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_PIPERUN_PROP_SETTING); |
|
544 |
cmd.ExecuteNonQuery(); |
|
545 |
|
|
546 |
foreach (var item in setting) |
|
547 |
{ |
|
548 |
cmd.CommandText = string.Format(@"INSERT INTO {0} |
|
549 |
(UID,ShowType,Name,DisplayName,TableName,DataType,Value,Cond1_Name,Cond1_DisplayName,Cond1_TableName,Cond1_DataType,Cond1_Value,Cond2_Name,Cond2_DisplayName,Cond2_TableName,Cond2_DataType,Cond2_Value,SortOrder) |
|
550 |
VALUES |
|
551 |
(@UID,@ShowType,@Name,@DisplayName,@TableName,@DataType,@Value,@Cond1_Name,@Cond1_DisplayName,@Cond1_TableName,@Cond1_DataType,@Cond1_Value,@Cond2_Name,@Cond2_DisplayName,@Cond2_TableName,@Cond2_DataType,@Cond2_Value,@SortOrder)" |
|
552 |
, SPPID_PIPERUN_PROP_SETTING); |
|
553 |
cmd.Parameters.Clear(); |
|
554 |
cmd.Parameters.AddWithValue("@UID" , item.UID); |
|
555 |
cmd.Parameters.AddWithValue("@ShowType" , item.ShowType); |
|
556 |
cmd.Parameters.AddWithValue("@Name" , item.Name); |
|
557 |
cmd.Parameters.AddWithValue("@DisplayName" , item.DisplayName); |
|
558 |
cmd.Parameters.AddWithValue("@TableName" , item.TableName); |
|
559 |
cmd.Parameters.AddWithValue("@DataType" , item.DataType); |
|
560 |
cmd.Parameters.AddWithValue("@Value" , item.Value); |
|
561 |
cmd.Parameters.AddWithValue("@Cond1_Name" , item.Cond1_Name); |
|
562 |
cmd.Parameters.AddWithValue("@Cond1_DisplayName" , item.Cond1_DisplayName); |
|
563 |
cmd.Parameters.AddWithValue("@Cond1_TableName" , item.Cond1_TableName); |
|
564 |
cmd.Parameters.AddWithValue("@Cond1_DataType" , item.Cond1_DataType); |
|
565 |
cmd.Parameters.AddWithValue("@Cond1_Value" , item.Cond1_Value); |
|
566 |
cmd.Parameters.AddWithValue("@Cond2_Name" , item.Cond2_Name); |
|
567 |
cmd.Parameters.AddWithValue("@Cond2_DisplayName" , item.Cond2_DisplayName); |
|
568 |
cmd.Parameters.AddWithValue("@Cond2_TableName" , item.Cond2_TableName); |
|
569 |
cmd.Parameters.AddWithValue("@Cond2_DataType" , item.Cond2_DataType); |
|
570 |
cmd.Parameters.AddWithValue("@Cond2_Value" , item.Cond2_Value); |
|
571 |
cmd.Parameters.AddWithValue("@SortOrder" , item.SortOrder); |
|
572 |
cmd.ExecuteNonQuery(); |
|
573 |
} |
|
574 |
} |
|
575 |
connection.Close(); |
|
576 |
} |
|
577 |
catch (Exception ex) |
|
578 |
{ |
|
579 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
580 |
return false; |
|
581 |
} |
|
582 |
finally |
|
583 |
{ |
|
584 |
connection.Dispose(); |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
|
589 |
{ |
|
590 |
using (SqlConnection connection = GetSqlConnection()) |
|
591 |
{ |
|
592 |
try |
|
593 |
{ |
|
594 |
if (connection != null && connection.State == ConnectionState.Open) |
|
595 |
{ |
|
596 |
using (SqlCommand cmd = connection.CreateCommand()) |
|
597 |
{ |
|
598 |
cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_PIPERUN_PROP_SETTING); |
|
599 |
cmd.ExecuteNonQuery(); |
|
600 |
|
|
601 |
foreach (var item in setting) |
|
602 |
{ |
|
603 |
cmd.CommandText = string.Format(@"INSERT INTO {0} |
|
604 |
(UID,ShowType,Name,DisplayName,TableName,DataType,Value,Cond1_Name,Cond1_DisplayName,Cond1_TableName,Cond1_DataType,Cond1_Value,Cond2_Name,Cond2_DisplayName,Cond2_TableName,Cond2_DataType,Cond2_Value,SortOrder) |
|
605 |
VALUES |
|
606 |
(@UID,@ShowType,@Name,@DisplayName,@TableName,@DataType,@Value,@Cond1_Name,@Cond1_DisplayName,@Cond1_TableName,@Cond1_DataType,@Cond1_Value,@Cond2_Name,@Cond2_DisplayName,@Cond2_TableName,@Cond2_DataType,@Cond2_Value,@SortOrder)" |
|
607 |
, SPPID_PIPERUN_PROP_SETTING); |
|
608 |
cmd.Parameters.Clear(); |
|
609 |
cmd.Parameters.AddWithValue("@UID" , item.UID); |
|
610 |
cmd.Parameters.AddWithValue("@ShowType" , item.ShowType); |
|
611 |
cmd.Parameters.AddWithValue("@Name" , item.Name); |
|
612 |
cmd.Parameters.AddWithValue("@DisplayName" , item.DisplayName); |
|
613 |
cmd.Parameters.AddWithValue("@TableName" , item.TableName); |
|
614 |
cmd.Parameters.AddWithValue("@DataType" , item.DataType); |
|
615 |
cmd.Parameters.AddWithValue("@Value" , item.Value); |
|
616 |
cmd.Parameters.AddWithValue("@Cond1_Name" , item.Cond1_Name); |
|
617 |
cmd.Parameters.AddWithValue("@Cond1_DisplayName" , item.Cond1_DisplayName); |
|
618 |
cmd.Parameters.AddWithValue("@Cond1_TableName" , item.Cond1_TableName); |
|
619 |
cmd.Parameters.AddWithValue("@Cond1_DataType" , item.Cond1_DataType); |
|
620 |
cmd.Parameters.AddWithValue("@Cond1_Value" , item.Cond1_Value); |
|
621 |
cmd.Parameters.AddWithValue("@Cond2_Name" , item.Cond2_Name); |
|
622 |
cmd.Parameters.AddWithValue("@Cond2_DisplayName" , item.Cond2_DisplayName); |
|
623 |
cmd.Parameters.AddWithValue("@Cond2_TableName" , item.Cond2_TableName); |
|
624 |
cmd.Parameters.AddWithValue("@Cond2_DataType" , item.Cond2_DataType); |
|
625 |
cmd.Parameters.AddWithValue("@Cond2_Value" , item.Cond2_Value); |
|
626 |
cmd.Parameters.AddWithValue("@SortOrder" , item.SortOrder); |
|
627 |
cmd.ExecuteNonQuery(); |
|
628 |
} |
|
629 |
} |
|
630 |
connection.Close(); |
|
631 |
} |
|
632 |
else |
|
633 |
return false; |
|
634 |
} |
|
635 |
catch (Exception ex) |
|
636 |
{ |
|
637 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
638 |
return false; |
|
639 |
} |
|
640 |
finally |
|
641 |
{ |
|
642 |
if (connection != null) |
|
643 |
connection.Dispose(); |
|
644 |
} |
|
645 |
} |
|
646 |
} |
|
647 |
|
|
648 |
return true; |
|
649 |
} |
|
513 | 650 |
|
514 | 651 |
public static DataTable SelectSetting() |
515 | 652 |
{ |
... | ... | |
1461 | 1598 |
return dt; |
1462 | 1599 |
} |
1463 | 1600 |
|
1601 |
public static DataTable SelectPipeRunPropSetting() |
|
1602 |
{ |
|
1603 |
DataTable dt = new DataTable(); |
|
1604 |
Project_Info projectInfo = Project_Info.GetInstance(); |
|
1605 |
if (projectInfo.DBType == ID2DB_Type.SQLite) |
|
1606 |
{ |
|
1607 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true)) |
|
1608 |
{ |
|
1609 |
try |
|
1610 |
{ |
|
1611 |
connection.Open(); |
|
1612 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
1613 |
{ |
|
1614 |
cmd.CommandText = string.Format(@" |
|
1615 |
SELECT s.UID, s.ShowType, s.Name, s.DisplayName, s.TableName, s.DataType, s.Value, s.Cond1_Name, s.Cond1_DisplayName, s.Cond1_TableName, s.Cond1_DataType, s.Cond1_Value, s.Cond2_Name, s.Cond2_DisplayName, s.Cond2_TableName, s.Cond2_DataType, s.Cond2_Value, s.SortOrder |
|
1616 |
FROM {0} as s |
|
1617 |
ORDER BY s.SortOrder ASC;", SPPID_PIPERUN_PROP_SETTING); |
|
1618 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
1619 |
dt.Load(dr); |
|
1620 |
} |
|
1621 |
connection.Close(); |
|
1622 |
} |
|
1623 |
catch (Exception ex) |
|
1624 |
{ |
|
1625 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
1626 |
} |
|
1627 |
finally |
|
1628 |
{ |
|
1629 |
connection.Dispose(); |
|
1630 |
} |
|
1631 |
} |
|
1632 |
} |
|
1633 |
else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
|
1634 |
{ |
|
1635 |
using (SqlConnection connection = GetSqlConnection()) |
|
1636 |
{ |
|
1637 |
try |
|
1638 |
{ |
|
1639 |
if (connection != null && connection.State == ConnectionState.Open) |
|
1640 |
{ |
|
1641 |
using (SqlCommand cmd = connection.CreateCommand()) |
|
1642 |
{ |
|
1643 |
cmd.CommandText = string.Format(@" |
|
1644 |
SELECT s.UID, s.ShowType, s.Name, s.DisplayName, s.TableName, s.DataType, s.Value, s.Cond1_Name, s.Cond1_DisplayName, s.Cond1_TableName, s.Cond1_DataType, s.Cond1_Value, s.Cond2Name, s.Cond2_DisplayName, s.Cond2_TableName, s.Cond2_DataType, s.Cond2_Value, s.SortOrder |
|
1645 |
FROM {0} as s |
|
1646 |
ORDER BY s.SortOrder ASC;", SPPID_PIPERUN_PROP_SETTING); |
|
1647 |
using (SqlDataReader dr = cmd.ExecuteReader()) |
|
1648 |
dt.Load(dr); |
|
1649 |
} |
|
1650 |
connection.Close(); |
|
1651 |
} |
|
1652 |
} |
|
1653 |
catch (Exception ex) |
|
1654 |
{ |
|
1655 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
1656 |
} |
|
1657 |
finally |
|
1658 |
{ |
|
1659 |
if (connection != null) |
|
1660 |
connection.Dispose(); |
|
1661 |
} |
|
1662 |
} |
|
1663 |
} |
|
1664 |
|
|
1665 |
return dt; |
|
1666 |
} |
|
1667 |
|
|
1668 |
public static DataTable SelectMappedPipeProperties() |
|
1669 |
{ |
|
1670 |
DataTable dt = new DataTable(); |
|
1671 |
Project_Info projectInfo = Project_Info.GetInstance(); |
|
1672 |
if (projectInfo.DBType == ID2DB_Type.SQLite) |
|
1673 |
{ |
|
1674 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true)) |
|
1675 |
{ |
|
1676 |
try |
|
1677 |
{ |
|
1678 |
connection.Open(); |
|
1679 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
1680 |
{ |
|
1681 |
cmd.CommandText = string.Format(@" |
|
1682 |
SELECT DISTINCT sam.SPPID_ATTRIBUTE |
|
1683 |
FROM {0} sam |
|
1684 |
LEFT JOIN {1} sa |
|
1685 |
ON sam.UID = sa.UID |
|
1686 |
LEFT JOIN {2} st |
|
1687 |
ON sa.SymbolType_UID = st.UID |
|
1688 |
LEFT JOIN {3} as lp |
|
1689 |
ON sam.UID = lp.UID |
|
1690 |
WHERE sam.SPPID_ATTRIBUTE is not null |
|
1691 |
AND (st.Category = 'Line' or lp.UID is not null);", SPPID_ATTRIBUTE_MAPPING_TABLE, SymbolAttribute_TABLE, SymbolType_TABLE, LineProperties_TABLE); |
|
1692 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
1693 |
dt.Load(dr); |
|
1694 |
} |
|
1695 |
connection.Close(); |
|
1696 |
} |
|
1697 |
catch (Exception ex) |
|
1698 |
{ |
|
1699 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
1700 |
} |
|
1701 |
finally |
|
1702 |
{ |
|
1703 |
connection.Dispose(); |
|
1704 |
} |
|
1705 |
} |
|
1706 |
} |
|
1707 |
else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
|
1708 |
{ |
|
1709 |
using (SqlConnection connection = GetSqlConnection()) |
|
1710 |
{ |
|
1711 |
try |
|
1712 |
{ |
|
1713 |
if (connection != null && connection.State == ConnectionState.Open) |
|
1714 |
{ |
|
1715 |
using (SqlCommand cmd = connection.CreateCommand()) |
|
1716 |
{ |
|
1717 |
cmd.CommandText = string.Format(@" |
|
1718 |
SELECT DISTINCT sam.SPPID_ATTRIBUTE |
|
1719 |
FROM {0} sam |
|
1720 |
LEFT JOIN {1} sa |
|
1721 |
ON sam.UID = sa.UID |
|
1722 |
LEFT JOIN {2} st |
|
1723 |
ON sa.SymbolType_UID = st.UID |
|
1724 |
LEFT JOIN {3} as lp |
|
1725 |
ON sam.UID = lp.UID |
|
1726 |
WHERE sam.SPPID_ATTRIBUTE is not null |
|
1727 |
AND (st.Category = 'Line' or lp.UID is not null);", SPPID_ATTRIBUTE_MAPPING_TABLE, SymbolAttribute_TABLE, SymbolType_TABLE, LineProperties_TABLE); |
|
1728 |
using (SqlDataReader dr = cmd.ExecuteReader()) |
|
1729 |
dt.Load(dr); |
|
1730 |
} |
|
1731 |
connection.Close(); |
|
1732 |
} |
|
1733 |
} |
|
1734 |
catch (Exception ex) |
|
1735 |
{ |
|
1736 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
1737 |
} |
|
1738 |
finally |
|
1739 |
{ |
|
1740 |
if (connection != null) |
|
1741 |
connection.Dispose(); |
|
1742 |
} |
|
1743 |
} |
|
1744 |
} |
|
1745 |
|
|
1746 |
DataTable dtPipeRun = SPPID_DB.GetPipeRunProperties(false, true); |
|
1747 |
DataTable resultDT = dtPipeRun.Clone(); |
|
1748 |
if (dt != null) |
|
1749 |
{ |
|
1750 |
List<string> filterList = new List<string>(); |
|
1751 |
foreach (DataRow dr in dt.Rows) |
|
1752 |
{ |
|
1753 |
filterList.Add("'" + dr["SPPID_ATTRIBUTE"].ToString() + "'"); |
|
1754 |
} |
|
1755 |
string filter = string.Join(",", filterList.ToArray()); |
|
1756 |
DataRow[] dataRows = dtPipeRun.Select(string.Format("NAME IN ({0})", filter)); |
|
1757 |
|
|
1758 |
resultDT.Rows.Add(resultDT.NewRow()); |
|
1759 |
foreach (DataRow dr in dataRows) |
|
1760 |
{ |
|
1761 |
resultDT.Rows.Add(dr.ItemArray); |
|
1762 |
} |
|
1763 |
} |
|
1764 |
return resultDT; |
|
1765 |
} |
|
1766 |
|
|
1464 | 1767 |
public static DataTable SelectSymbolType() |
1465 | 1768 |
{ |
1466 | 1769 |
DataTable dt = new DataTable(); |
내보내기 Unified diff