프로젝트

일반

사용자정보

개정판 ee781888

IDee7818882fc4aea5069ad2d2cadb7a9a2d51d5b7
상위 7a56b228
하위 ae3689fb

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

dev issue #1227 : end attribute mapping (UDA)

Change-Id: I42de16d1f4fd8c8bd6eec37f931a2f3b114e181d

차이점 보기:

DTI_PID/APIDConverter/DB/Project_DB.cs
762 762

  
763 763
            return true;
764 764
        }
765
        public static bool InsertAttributeMapping(List<Tuple<string, string, string>> datas)
766
        {
767
            Project_Info projectInfo = Project_Info.GetInstance();
768
            if (projectInfo.DBType == ID2DB_Type.SQLite)
769
            {
770
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
771
                {
772
                    try
773
                    {
774
                        connection.Open();
775
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
776
                        {
777
                            try
778
                            {
779
                                using (SQLiteCommand cmd = connection.CreateCommand())
780
                                {
781
                                    foreach (var item in datas)
782
                                    {
783
                                        cmd.Parameters.Clear();
784
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, APID_ATTRIBUTE, APID_ATTRIBUTE_TYPE) VALUES (@UID, @APID_ATTRIBUTE, @APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE);
785
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
786
                                        cmd.Parameters.AddWithValue("@APID_ATTRIBUTE", item.Item2);
787
                                        cmd.Parameters.AddWithValue("@APID_ATTRIBUTE_TYPE", item.Item3);
788
                                        cmd.ExecuteNonQuery();
789
                                    }
790
                                }
791
                                transaction.Commit();
792
                                connection.Close();
793
                            }
794
                            catch (Exception ex)
795
                            {
796
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
797
                                transaction.Rollback();
798
                                return false;
799
                            }
800
                            finally
801
                            {
802
                                transaction.Dispose();
803
                            }
804
                        }
805
                    }
806
                    catch (Exception ex)
807
                    {
808
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
809
                        return false;
810
                    }
811
                    finally
812
                    {
813
                        connection.Dispose();
814
                    }
815
                }
816
            }
817
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
818
            {
819
                using (SqlConnection connection = GetSqlConnection())
820
                {
821
                    try
822
                    {
823
                        if (connection != null && connection.State == ConnectionState.Open)
824
                        {
825
                            using (SqlCommand cmd = connection.CreateCommand())
826
                            {
827
                                foreach (var item in datas)
828
                                {
829
                                    cmd.Parameters.Clear();
830
                                    cmd.CommandText = string.Format(@"
831
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
832
                                        UPDATE {0} SET APID_ATTRIBUTE = @APID_ATTRIBUTE, APID_ATTRIBUTE_TYPE = @APID_ATTRIBUTE_TYPE WHERE UID = @UID
833
                                    ELSE
834
                                        INSERT INTO {0} (UID, APID_ATTRIBUTE, APID_ATTRIBUTE_TYPE) VALUES (@UID, @APID_ATTRIBUTE, @APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE, item.Item1);
835
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
836
                                    if (string.IsNullOrEmpty(item.Item2))
837
                                        cmd.Parameters.AddWithValue("@APID_ATTRIBUTE", DBNull.Value);
838
                                    else
839
                                        cmd.Parameters.AddWithValue("@APID_ATTRIBUTE", item.Item2);
840
                                    if (string.IsNullOrEmpty(item.Item3))
841
                                        cmd.Parameters.AddWithValue("@APID_ATTRIBUTE_TYPE", DBNull.Value);
842
                                    else
843
                                        cmd.Parameters.AddWithValue("@APID_ATTRIBUTE_TYPE", item.Item3);
844

  
845
                                    cmd.ExecuteNonQuery();
846
                                }
847
                            }
848
                            connection.Close();
849
                        }
850
                    }
851
                    catch (Exception ex)
852
                    {
853
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
854
                        return false;
855
                    }
856
                    finally
857
                    {
858
                        if (connection != null)
859
                            connection.Dispose();
860
                    }
861
                }
862
            }
863

  
864
            return true;
865
        }
765 866
        public static DataTable SelectProjectAttribute()
766 867
        {
767 868
            DataTable dt = new DataTable();
DTI_PID/APIDConverter/Form/MappingForm.Designer.cs
29 29
        private void InitializeComponent()
30 30
        {
31 31
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MappingForm));
32
            DevExpress.XtraBars.Ribbon.GalleryItemGroup galleryItemGroup1 = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
32
            DevExpress.XtraBars.Ribbon.GalleryItemGroup galleryItemGroup2 = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
33 33
            this.ribbonControl = new DevExpress.XtraBars.Ribbon.RibbonControl();
34 34
            this.layoutControl1 = new DevExpress.XtraLayout.LayoutControl();
35 35
            this.pictureEditMappedOPCOut = new DevExpress.XtraEditors.PictureEdit();
......
268 268
            // 
269 269
            // 
270 270
            // 
271
            galleryItemGroup1.Caption = "Items";
271
            galleryItemGroup2.Caption = "Items";
272 272
            this.galleryControlAvevaSymbols.Gallery.Groups.AddRange(new DevExpress.XtraBars.Ribbon.GalleryItemGroup[] {
273
            galleryItemGroup1});
273
            galleryItemGroup2});
274 274
            this.galleryControlAvevaSymbols.Gallery.ItemDoubleClick += new DevExpress.XtraBars.Ribbon.GalleryItemClickEventHandler(this.galleryControlAvevaSymbols_Gallery_ItemDoubleClick);
275 275
            this.galleryControlAvevaSymbols.Location = new System.Drawing.Point(814, 273);
276 276
            this.galleryControlAvevaSymbols.Name = "galleryControlAvevaSymbols";
......
387 387
            // 
388 388
            this.tabbedControlGroup.Location = new System.Drawing.Point(0, 0);
389 389
            this.tabbedControlGroup.Name = "tabbedControlGroup";
390
            this.tabbedControlGroup.SelectedTabPage = this.GroupAttribute;
390
            this.tabbedControlGroup.SelectedTabPage = this.GroupSymbol;
391 391
            this.tabbedControlGroup.Size = new System.Drawing.Size(785, 675);
392 392
            this.tabbedControlGroup.TabPages.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] {
393 393
            this.GroupSymbol,
DTI_PID/APIDConverter/Form/MappingForm.cs
327 327
            }
328 328
            #endregion
329 329

  
330
            List<Tuple<string, string, string>> attributeDatas = new List<Tuple<string, string, string>>();
331
            #region Attribute
332
            DataTable attributeDT = gridControlAttribute.DataSource as DataTable;
333
            foreach (DataRow row in attributeDT.Rows)
334
            {
335
                string uid = row["UID"].ToString();
336
                string apidAttr = row["APID_ATTRIBUTE"].ToString();
337
                string apidAttrType = string.Empty;
338
                if (!string.IsNullOrEmpty(apidAttr))
339
                {
340
                    string[] split = apidAttr.Split(new char[] { '|' });
341
                    apidAttrType = split[split.Length - 1];
342
                }
343

  
344
                attributeDatas.Add(new Tuple<string, string, string>(uid, apidAttr, apidAttrType));
345
            }
346
            #endregion
330 347
            if (Project_DB.InsertSymbolMapping(symbolDatas) &&
331
                Project_DB.InsertOPCMapping(opcDatas))
348
                Project_DB.InsertOPCMapping(opcDatas) &&
349
                Project_DB.InsertAttributeMapping(attributeDatas))
332 350
                MessageBox.Show("Save Success!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
333 351
            else
334 352
                MessageBox.Show("Save Fail!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);

내보내기 Unified diff

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