개정판 7a56b228
dev issue #1227 : add attribute mapping ui and function
Change-Id: Ia0c59476dc563bc7fd62588bbce706bd18b7f72a
DTI_PID/APIDConverter/DB/Project_DB.cs | ||
---|---|---|
18 | 18 |
{ |
19 | 19 |
const string APID_SYMBOL_MAPPING_TABLE = "T_APID_SYMBOL_MAPPING"; |
20 | 20 |
const string APID_OPC_MAPPING_TABLE = "T_APID_OPC_MAPPING"; |
21 |
const string APID_ATTRIBUTE_MAPPING_TABLE = "T_APID_ATTRIBUTE_MAPPING"; |
|
21 | 22 |
|
22 | 23 |
const string LineProperties_TABLE = "LineProperties"; |
23 | 24 |
const string LineTypes_TABLE = "LineTypes"; |
... | ... | |
84 | 85 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, IN_SYMBOL TEXT, OUT_SYMBOL TEXT)", APID_OPC_MAPPING_TABLE); |
85 | 86 |
cmd.ExecuteNonQuery(); |
86 | 87 |
} |
88 |
if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_MAPPING_TABLE)).Length == 0) |
|
89 |
{ |
|
90 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, APID_ATTRIBUTE TEXT, APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE); |
|
91 |
cmd.ExecuteNonQuery(); |
|
92 |
} |
|
87 | 93 |
} |
88 | 94 |
} |
89 | 95 |
result = true; |
... | ... | |
126 | 132 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, IN_SYMBOL varchar(MAX), OUT_SYMBOL varchar(MAX))", APID_OPC_MAPPING_TABLE); |
127 | 133 |
cmd.ExecuteNonQuery(); |
128 | 134 |
} |
135 |
if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_MAPPING_TABLE)).Length == 0) |
|
136 |
{ |
|
137 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, APID_ATTRIBUTE varchar(MAX), APID_ATTRIBUTE_TYPE varchar(MAX))", APID_ATTRIBUTE_MAPPING_TABLE); |
|
138 |
cmd.ExecuteNonQuery(); |
|
139 |
} |
|
129 | 140 |
} |
130 | 141 |
} |
131 | 142 |
result = true; |
... | ... | |
751 | 762 |
|
752 | 763 |
return true; |
753 | 764 |
} |
765 |
public static DataTable SelectProjectAttribute() |
|
766 |
{ |
|
767 |
DataTable dt = new DataTable(); |
|
768 |
Project_Info projectInfo = Project_Info.GetInstance(); |
|
769 |
if (projectInfo.DBType == ID2DB_Type.SQLite) |
|
770 |
{ |
|
771 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
|
772 |
{ |
|
773 |
try |
|
774 |
{ |
|
775 |
connection.Open(); |
|
776 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
777 |
{ |
|
778 |
cmd.CommandText = string.Format(@" |
|
779 |
SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.APID_ATTRIBUTE, spa.APID_ATTRIBUTE_TYPE, sp.APID_SYMBOL, sa.Property |
|
780 |
FROM {1} as sa, {0} as st |
|
781 |
LEFT OUTER JOIN {2} as sp |
|
782 |
ON sa.UID = SP.UID |
|
783 |
LEFT OUTER JOIN {3} as spa |
|
784 |
ON sa.UID = spa.UID |
|
785 |
WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, APID_SYMBOL_MAPPING_TABLE, APID_ATTRIBUTE_MAPPING_TABLE); |
|
786 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
787 |
dt.Load(dr); |
|
788 |
} |
|
789 |
connection.Close(); |
|
790 |
} |
|
791 |
catch (Exception ex) |
|
792 |
{ |
|
793 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
794 |
} |
|
795 |
finally |
|
796 |
{ |
|
797 |
connection.Dispose(); |
|
798 |
} |
|
799 |
} |
|
800 |
} |
|
801 |
else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
|
802 |
{ |
|
803 |
using (SqlConnection connection = GetSqlConnection()) |
|
804 |
{ |
|
805 |
try |
|
806 |
{ |
|
807 |
if (connection != null && connection.State == ConnectionState.Open) |
|
808 |
{ |
|
809 |
using (SqlCommand cmd = connection.CreateCommand()) |
|
810 |
{ |
|
811 |
cmd.CommandText = string.Format(@" |
|
812 |
SELECT sa.UID, sa.DisplayAttribute, st.Type, spa.APID_ATTRIBUTE, spa.APID_ATTRIBUTE_TYPE, sp.APID_SYMBOL, sa.Property |
|
813 |
FROM {1} as sa |
|
814 |
LEFT OUTER JOIN {2} as sp |
|
815 |
ON sa.UID = SP.UID |
|
816 |
LEFT OUTER JOIN {3} as spa |
|
817 |
ON sa.UID = spa.UID |
|
818 |
LEFT OUTER JOIN {0} as st |
|
819 |
ON sa.SymbolType_UID = st.UID |
|
820 |
WHERE (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, APID_SYMBOL_MAPPING_TABLE, APID_ATTRIBUTE_MAPPING_TABLE); |
|
821 |
using (SqlDataReader dr = cmd.ExecuteReader()) |
|
822 |
dt.Load(dr); |
|
823 |
} |
|
824 |
connection.Close(); |
|
825 |
} |
|
826 |
} |
|
827 |
catch (Exception ex) |
|
828 |
{ |
|
829 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
830 |
} |
|
831 |
finally |
|
832 |
{ |
|
833 |
if (connection != null) |
|
834 |
connection.Dispose(); |
|
835 |
} |
|
836 |
} |
|
837 |
} |
|
838 |
|
|
839 |
|
|
840 |
return dt; |
|
841 |
} |
|
754 | 842 |
#endregion |
755 | 843 |
|
756 | 844 |
#region AVEVA |
... | ... | |
956 | 1044 |
|
957 | 1045 |
return dt; |
958 | 1046 |
} |
959 |
|
|
960 | 1047 |
public static DataTable SelectUDADetails() |
961 | 1048 |
{ |
962 | 1049 |
DataTable dt = new DataTable(); |
내보내기 Unified diff