프로젝트

일반

사용자정보

개정판 faba1fc7

IDfaba1fc77991111b6c76977965f699f78ff024e5
상위 d03dde83
하위 ca8ba1c8

gaqhf 이(가) 약 5년 전에 추가함

dev issue #1230 : edit aveva AttributeInfo

Change-Id: If3a14f65dc236eb73a3af73b0d26104ca0f91aa6

차이점 보기:

DTI_PID/APIDConverter/AutoModeling.cs
356 356
                {
357 357
                    AttributeInfo info = avevaInfo.AttributeInfo.Find(x => x.UID == attribute.UID);
358 358
                    if (info != null && !string.IsNullOrEmpty(info.APID_ATTRIBUTE))
359
                    {
360
                        if (info.APID_ATTRIBUTE_TYPE == AvevaAttributeType.UDA)
361
                            datas.Add(new Tuple<string, string>("UDA" + info.APID_ATTRIBUTE, attribute.VALUE));
362
                        else
363
                            datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE));
364
                    }
359
                        datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE));
365 360
                }
366 361
                if (datas.Count > 0)
367 362
                {
......
380 375
                {
381 376
                    AttributeInfo info = avevaInfo.AttributeInfo.Find(x => x.UID == attribute.UID);
382 377
                    if (info != null && !string.IsNullOrEmpty(info.APID_ATTRIBUTE))
383
                    {
384
                        if (info.APID_ATTRIBUTE_TYPE == AvevaAttributeType.UDA)
385
                            datas.Add(new Tuple<string, string>("UDA" + info.APID_ATTRIBUTE, attribute.VALUE));
386
                        else
387
                            datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE));
388
                    }
378
                        datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE));
389 379
                }
390 380
                if (datas.Count > 0)
391 381
                {
DTI_PID/APIDConverter/AvevaInfo.cs
59 59
                AttributeInfo info = new AttributeInfo();
60 60
                info.UID = DBNull.Value.Equals(row["UID"]) ? string.Empty : row["UID"].ToString();
61 61
                info.APID_ATTRIBUTE = DBNull.Value.Equals(row["APID_ATTRIBUTE"]) ? string.Empty : row["APID_ATTRIBUTE"].ToString();
62
                string sType = DBNull.Value.Equals(row["APID_ATTRIBUTE_TYPE"]) ? string.Empty : row["APID_ATTRIBUTE_TYPE"].ToString();
63
                if (!string.IsNullOrEmpty(info.APID_ATTRIBUTE) && !string.IsNullOrEmpty(sType))
64
                {
65
                    string sRemove = "|" + sType;
66
                    info.APID_ATTRIBUTE = info.APID_ATTRIBUTE.Remove(info.APID_ATTRIBUTE.LastIndexOf(sRemove), sRemove.Length);
67
                    AvevaAttributeType type;
68
                    if (Enum.TryParse(sType, out type))
69
                        info.APID_ATTRIBUTE_TYPE = type;
70
                }
62
                //string sType = DBNull.Value.Equals(row["APID_ATTRIBUTE_TYPE"]) ? string.Empty : row["APID_ATTRIBUTE_TYPE"].ToString();
63
                //if (!string.IsNullOrEmpty(info.APID_ATTRIBUTE) && !string.IsNullOrEmpty(sType))
64
                //{
65
                //    string sRemove = "|" + sType;
66
                //    info.APID_ATTRIBUTE = info.APID_ATTRIBUTE.Remove(info.APID_ATTRIBUTE.LastIndexOf(sRemove), sRemove.Length);
67
                //    AvevaAttributeType type;
68
                //    if (Enum.TryParse(sType, out type))
69
                //        info.APID_ATTRIBUTE_TYPE = type;
70
                //}
71 71
                avevaInfo.AttributeInfo.Add(info);
72 72
            }
73 73
            dt.Dispose();
......
86 86
    {
87 87
        public string UID { get; set; }
88 88
        public string APID_ATTRIBUTE { get; set; }
89
        public AvevaAttributeType APID_ATTRIBUTE_TYPE { get; set; }
90
    }
91

  
92
    public enum AvevaAttributeType
93
    {
94
        None,
95
        UDA,
96
        PipeAttribute,
97 89
    }
98 90
}
DTI_PID/APIDConverter/DB/Project_DB.cs
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 21
        const string APID_ATTRIBUTE_MAPPING_TABLE = "T_APID_ATTRIBUTE_MAPPING";
22
        const string APID_ATTRIBUTE_TABLE = "T_APID_ATTRIBUTE";
22 23

  
23 24
        const string LineProperties_TABLE = "LineProperties";
24 25
        const string LineTypes_TABLE = "LineTypes";
......
87 88
                                    }
88 89
                                    if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
89 90
                                    {
90
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, APID_ATTRIBUTE TEXT, APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE);
91
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, APID_ATTRIBUTE TEXT, APID_ATTRIBUTE_TYPE TEXT)", APID_ATTRIBUTE_MAPPING_TABLE);
92
                                        cmd.ExecuteNonQuery();
93
                                    }
94
                                    if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_TABLE)).Length == 0)
95
                                    {
96
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (LEVEL1 TEXT, LEVEL2 TEXT, ATTRIBUTE_KEY TEXT, ATTRIBUTE_NAME TEXT)", APID_ATTRIBUTE_TABLE);
91 97
                                        cmd.ExecuteNonQuery();
92 98
                                    }
93 99
                                }
......
137 143
                                        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 144
                                        cmd.ExecuteNonQuery();
139 145
                                    }
146
                                    if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_TABLE)).Length == 0)
147
                                    {
148
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (LEVEL1 varchar(255), LEVEL2 varchar(255), ATTRIBUTE_KEY varchar(255), ATTRIBUTE_NAME varchar(255))", APID_ATTRIBUTE_TABLE);
149
                                        cmd.ExecuteNonQuery();
150
                                    }
140 151
                                }
141 152
                            }
142 153
                            result = true;
......
863 874

  
864 875
            return true;
865 876
        }
877
        public static bool InsertAPIDAttribute(List<Tuple<string, string, string, string>> datas)
878
        {
879
            Project_Info projectInfo = Project_Info.GetInstance();
880
            if (projectInfo.DBType == ID2DB_Type.SQLite)
881
            {
882
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
883
                {
884
                    try
885
                    {
886
                        connection.Open();
887
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
888
                        {
889
                            try
890
                            {
891
                                using (SQLiteCommand cmd = connection.CreateCommand())
892
                                {
893
                                    foreach (var item in datas)
894
                                    {
895
                                        cmd.Parameters.Clear();
896
                                        cmd.CommandText = string.Format(@"
897
                                        IF EXISTS (SELECT * FROM {0} WHERE LEVEL1 = '{1}' AND LEVEL2 = '{2}' AND ATTRIBUTE_KEY = '{3}')
898
                                            UPDATE {0} SET ATTRIBUTE_NAME = @ATTRIBUTE_NAME WHERE LEVEL1 = '{1}' AND LEVEL2 = '{2}' AND ATTRIBUTE_KEY = '{3}'
899
                                        ELSE
900
                                            INSERT INTO {0} (LEVEL1, LEVEL2, ATTRIBUTE_KEY, ATTRIBUTE_NAME) VALUES (@LEVEL1, @LEVEL2, @ATTRIBUTE_KEY, @ATTRIBUTE_NAME)",
901
                                            APID_ATTRIBUTE_TABLE, item.Item1, item.Item2, item.Item3);
902
                                        cmd.Parameters.AddWithValue("@LEVEL1", item.Item1);
903
                                        cmd.Parameters.AddWithValue("@LEVEL2", item.Item2);
904
                                        cmd.Parameters.AddWithValue("@ATTRIBUTE_KEY", item.Item3);
905
                                        cmd.Parameters.AddWithValue("@ATTRIBUTE_NAME", item.Item4);
906
                                        cmd.ExecuteNonQuery();
907
                                    }
908
                                }
909
                                transaction.Commit();
910
                                connection.Close();
911
                            }
912
                            catch (Exception ex)
913
                            {
914
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
915
                                transaction.Rollback();
916
                                return false;
917
                            }
918
                            finally
919
                            {
920
                                transaction.Dispose();
921
                            }
922
                        }
923
                    }
924
                    catch (Exception ex)
925
                    {
926
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
927
                        return false;
928
                    }
929
                    finally
930
                    {
931
                        connection.Dispose();
932
                    }
933
                }
934
            }
935
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
936
            {
937
                using (SqlConnection connection = GetSqlConnection())
938
                {
939
                    try
940
                    {
941
                        if (connection != null && connection.State == ConnectionState.Open)
942
                        {
943
                            using (SqlCommand cmd = connection.CreateCommand())
944
                            {
945
                                foreach (var item in datas)
946
                                {
947
                                    cmd.Parameters.Clear();
948
                                    cmd.CommandText = string.Format(@"
949
                                    IF EXISTS (SELECT * FROM {0} WHERE LEVEL1 = '{1}' AND LEVEL2 = '{2}' AND ATTRIBUTE_KEY = '{3}')
950
                                        UPDATE {0} SET ATTRIBUTE_NAME = @ATTRIBUTE_NAME WHERE LEVEL1 = '{1}' AND LEVEL2 = '{2}' AND ATTRIBUTE_KEY = '{3}'
951
                                    ELSE
952
                                        INSERT INTO {0} (LEVEL1, LEVEL2, ATTRIBUTE_KEY, ATTRIBUTE_NAME) VALUES (@LEVEL1, @LEVEL2, @ATTRIBUTE_KEY, @ATTRIBUTE_NAME)",
953
                                        APID_ATTRIBUTE_TABLE, item.Item1, item.Item2, item.Item3);
954
                                    cmd.Parameters.AddWithValue("@LEVEL1", item.Item1);
955
                                    cmd.Parameters.AddWithValue("@LEVEL2", item.Item2);
956
                                    cmd.Parameters.AddWithValue("@ATTRIBUTE_KEY", item.Item3);
957
                                    cmd.Parameters.AddWithValue("@ATTRIBUTE_NAME", item.Item4);
958
                                    cmd.ExecuteNonQuery();
959
                                }
960
                            }
961
                            connection.Close();
962
                        }
963
                    }
964
                    catch (Exception ex)
965
                    {
966
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
967
                        return false;
968
                    }
969
                    finally
970
                    {
971
                        if (connection != null)
972
                            connection.Dispose();
973
                    }
974
                }
975
            }
976

  
977
            return true;
978
        }
866 979
        public static DataTable GetProjectAttribute()
867 980
        {
868 981
            DataTable dt = new DataTable();
......
1132 1245

  
1133 1246
            return dt;
1134 1247
        }
1248
        public static DataTable GetAPIDAttributeTable()
1249
        {
1250
            DataTable dt = new DataTable();
1251
            Project_Info projectInfo = Project_Info.GetInstance();
1252
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1253
            {
1254
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1255
                {
1256
                    try
1257
                    {
1258
                        connection.Open();
1259
                        using (SQLiteCommand cmd = connection.CreateCommand())
1260
                        {
1261
                            cmd.CommandText = string.Format("SELECT * FROM {0}", APID_ATTRIBUTE_TABLE);
1262
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1263
                                dt.Load(dr);
1264
                        }
1265
                        connection.Close();
1266
                    }
1267
                    catch (Exception ex)
1268
                    {
1269
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1270
                    }
1271
                    finally
1272
                    {
1273
                        connection.Dispose();
1274
                    }
1275
                }
1276
            }
1277
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1278
            {
1279
                using (SqlConnection connection = GetSqlConnection())
1280
                {
1281
                    try
1282
                    {
1283
                        if (connection != null && connection.State == ConnectionState.Open)
1284
                        {
1285
                            using (SqlCommand cmd = connection.CreateCommand())
1286
                            {
1287
                                cmd.CommandText = string.Format("SELECT * FROM {0}", APID_ATTRIBUTE_TABLE);
1288
                                using (SqlDataReader dr = cmd.ExecuteReader())
1289
                                    dt.Load(dr);
1290
                            }
1291
                            connection.Close();
1292
                        }
1293
                    }
1294
                    catch (Exception ex)
1295
                    {
1296
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1297
                    }
1298
                    finally
1299
                    {
1300
                        if (connection != null)
1301
                            connection.Dispose();
1302
                    }
1303
                }
1304
            }
1305

  
1306
            return dt;
1307
        }
1135 1308
        #endregion
1136 1309

  
1137 1310
        #region AVEVA
DTI_PID/APIDConverter/Form/MappingForm.cs
236 236
            gridViewLineNumberAttribute.ExpandAllGroups();
237 237

  
238 238
            #region set lookUpEdit
239
            DataTable attributeTable = APIDUtils.GetAPIDAttributes();
239
            DataTable attributeTable = Project_DB.GetAPIDAttributeTable();
240 240
            RepositoryItemGridLookUpEdit lookUpEdit = new RepositoryItemGridLookUpEdit();
241 241
            lookUpEdit.BeginInit();
242 242
            lookUpEdit.DataSource = attributeTable;
243
            lookUpEdit.DisplayMember = "DisplayMember";
244
            lookUpEdit.ValueMember = "Value";
243
            lookUpEdit.DisplayMember = "ATTRIBUTE_NAME";
244
            lookUpEdit.ValueMember = "ATTRIBUTE_KEY";
245 245
            lookUpEdit.NullText = "";
246 246
            lookUpEdit.BestFitMode = BestFitMode.BestFit;
247 247
            lookUpEdit.KeyUp += lookUpEdit_KeyUp;
......
249 249
            lookUpEdit.EndInit();
250 250

  
251 251
            lookUpEdit.View.OptionsBehavior.AutoPopulateColumns = false;
252
            DevExpress.XtraGrid.Columns.GridColumn colType = lookUpEdit.View.Columns.AddField("DisplayType");
253
            colType.GroupIndex = 0;
254
            colType.VisibleIndex = 0;
255
            colType.Caption = "Type";
256
            DevExpress.XtraGrid.Columns.GridColumn colStyle = lookUpEdit.View.Columns.AddField("Name");
257
            colStyle.VisibleIndex = 1;
252
            DevExpress.XtraGrid.Columns.GridColumn colLevel1 = lookUpEdit.View.Columns.AddField("LEVEL1");
253
            colLevel1.GroupIndex = 0;
254
            colLevel1.VisibleIndex = 0;
255
            colLevel1.Caption = "Item Type";
256
            DevExpress.XtraGrid.Columns.GridColumn colLevel2 = lookUpEdit.View.Columns.AddField("LEVEL2");
257
            colLevel2.GroupIndex = 1;
258
            colLevel2.VisibleIndex = 1;
259
            colLevel2.Caption = "Property";
260
            DevExpress.XtraGrid.Columns.GridColumn colName = lookUpEdit.View.Columns.AddField("ATTRIBUTE_NAME");
261
            colName.VisibleIndex = 2;
258 262
            #endregion
259 263

  
260 264
            gridControlLineNumberAttribute.RepositoryItems.Add(lookUpEdit);
......
291 295
            gridViewAttribute.Columns["Clear"].MaxWidth = 16;
292 296

  
293 297
            #region set lookUpEdit
294
            DataTable attributeTable = APIDUtils.GetAPIDAttributes();
298
            DataTable attributeTable = Project_DB.GetAPIDAttributeTable();
295 299
            RepositoryItemGridLookUpEdit lookUpEdit = new RepositoryItemGridLookUpEdit();
296 300
            lookUpEdit.BeginInit();
297 301
            lookUpEdit.DataSource = attributeTable;
298
            lookUpEdit.DisplayMember = "DisplayMember";
299
            lookUpEdit.ValueMember = "Value";
302
            lookUpEdit.DisplayMember = "ATTRIBUTE_NAME";
303
            lookUpEdit.ValueMember = "ATTRIBUTE_KEY";
300 304
            lookUpEdit.NullText = "";
301 305
            lookUpEdit.BestFitMode = BestFitMode.BestFit;
302 306
            lookUpEdit.KeyUp += lookUpEdit_KeyUp;
......
304 308
            lookUpEdit.EndInit();
305 309

  
306 310
            lookUpEdit.View.OptionsBehavior.AutoPopulateColumns = false;
307
            DevExpress.XtraGrid.Columns.GridColumn colType = lookUpEdit.View.Columns.AddField("DisplayType");
308
            colType.GroupIndex = 0;
309
            colType.VisibleIndex = 0;
310
            colType.Caption = "Type";
311
            DevExpress.XtraGrid.Columns.GridColumn colStyle = lookUpEdit.View.Columns.AddField("Name");
312
            colStyle.VisibleIndex = 1;
311
            DevExpress.XtraGrid.Columns.GridColumn colLevel1 = lookUpEdit.View.Columns.AddField("LEVEL1");
312
            colLevel1.GroupIndex = 0;
313
            colLevel1.VisibleIndex = 0;
314
            colLevel1.Caption = "Item Type";
315
            DevExpress.XtraGrid.Columns.GridColumn colLevel2 = lookUpEdit.View.Columns.AddField("LEVEL2");
316
            colLevel2.GroupIndex = 1;
317
            colLevel2.VisibleIndex = 1;
318
            colLevel2.Caption = "Property";
319
            DevExpress.XtraGrid.Columns.GridColumn colName = lookUpEdit.View.Columns.AddField("ATTRIBUTE_NAME");
320
            colName.VisibleIndex = 2;
313 321
            #endregion
314 322

  
315 323
            gridControlAttribute.RepositoryItems.Add(lookUpEdit);
DTI_PID/APIDConverter/Utils/APIDUtils.cs
146 146

  
147 147
            return list;
148 148
        }
149
        public static Dictionary<PID.Utilities.PipeLabelName, PID.Utilities.PipeLabelHelper.PipeDisplayLabelField> GetPipeAttribute()
150
        {
151
            return PID.Utilities.PipeLabelHelper.GetPipeDisplayLabelFields().ToDictionary(x => x.Key, y => y.Value);
152
        }
153
        private static System.Data.DataTable GetSymbolAttributes()
154
        {
155
            System.Data.DataTable dt = new System.Data.DataTable();
156
            dt.Columns.Add("Name", typeof(string));
157
            dt.Columns.Add("DisplayType", typeof(string));
158
            dt.Columns.Add("Value", typeof(string));
159
            dt.Columns.Add("DisplayMember", typeof(string));
160

  
161
            #region UDA
162
            System.Data.DataTable udaDT = Project_DB.SelectUDADetails();
163
            udaDT = udaDT.DefaultView.ToTable(true, "UDAName");
164
            string display = "User Defined Attribute";
165
            foreach (DataRow item in udaDT.Rows)
166
            {
167
                string name = (string)item["UDAName"];
168
                string value = item["UDAName"] + "|" + AvevaAttributeType.UDA;
169
                string displayMember = name + " | " + display;
170
                dt.Rows.Add(name, display, value, displayMember);
171
            }
172
                
173
            #endregion
174

  
175
            return dt;
176
        }
177
        private static System.Data.DataTable GetPipeAttributes()
178
        {
179
            System.Data.DataTable dt = new System.Data.DataTable();
180
            dt.Columns.Add("Name", typeof(string));
181
            dt.Columns.Add("DisplayType", typeof(string));
182
            dt.Columns.Add("Value", typeof(string));
183
            dt.Columns.Add("DisplayMember", typeof(string));
184

  
185
            string display = "Pipe Attribute";
186
            foreach (var item in PID.Utilities.PipeLabelHelper.GetPipeDisplayLabelFields())
187
            {
188
                string name = item.Value.FieldName;
189
                string value = item.Key + "|" + AvevaAttributeType.PipeAttribute;
190
                string displayMember = name + " | " + display;
191
                dt.Rows.Add(name, display, value, displayMember);
192
            }
193

  
194
            return dt;
195
        }
196
        public static System.Data.DataTable GetAPIDAttributes()
197
        {
198
            System.Data.DataTable attributeTable = new System.Data.DataTable();
199
            attributeTable.Columns.Add("Name", typeof(string));
200
            attributeTable.Columns.Add("DisplayType", typeof(string));
201
            attributeTable.Columns.Add("Value", typeof(string));
202
            attributeTable.Columns.Add("DisplayMember", typeof(string));
203

  
204
            attributeTable.Merge(GetSymbolAttributes());
205
            attributeTable.Merge(GetPipeAttributes());
206

  
207

  
208
            return attributeTable;
209
        }
210 149
        public static Entity GetEntityByHandle(long handle)
211 150
        {
212 151
            Entity entity = null;
DTI_PID/APIDConverter/Utils/AvevaThread.cs
229 229
        }
230 230
        public static void GetAttributeInformationFromForm()
231 231
        {
232
            List<Tuple<string, string, string, string>> datas = new List<Tuple<string, string, string, string>>();
232 233
            while (Running.HasFlag(ThreadType.GetAttributeInformationFromForm))
233 234
            {
234 235
                int handle = FindPropertiesFormHandle();
......
238 239
                    if (control != null && control.GetType() == typeof(ComponentPropertiesUI))
239 240
                    {
240 241
                        ComponentPropertiesUI UI = control as ComponentPropertiesUI;
242
                        
241 243
                        string level1 = UI.Text;
242 244
                        foreach (PropertyRegion region in UI.PropertyRegions)
243 245
                        {
244 246
                            string level2 = region.Title;
245 247
                            foreach (PropertyField field in region.PropertyFields)
246 248
                            {
247
                                string level3 = field.Key;
248
                                string displayName = field.Name;
249

  
250

  
249
                                string attributeKey = field.Key;
250
                                string attributeName = field.Name;
251
                                datas.Add(new Tuple<string, string, string, string>(level1, level2, attributeKey, attributeName));
251 252
                            }
252 253
                        }
253 254

  
......
261 262
                    }
262 263
                }
263 264
            }
265

  
266
            if (datas.Count > 0)
267
            {
268
                if (!Project_DB.InsertAPIDAttribute(datas))
269
                    System.Windows.Forms.MessageBox.Show("Fail save to database...", "APID Converter", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
270
            }
264 271
        }
265 272

  
273

  
266 274
        public static int FindPropertiesFormHandle()
267 275
        {
268 276
            int result = 0;

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)