프로젝트

일반

사용자정보

개정판 c8da68ce

IDc8da68ce1704a0fda58bc03696895db55657d922
상위 77475d87
하위 71aba947

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

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
DTI_PID/APIDConverter/Form/MappingForm.cs
45 45
                RepositoryItemButtonEdit clearButton = new RepositoryItemButtonEdit();
46 46
                clearButton.Buttons[0].Kind = ButtonPredefines.Glyph;
47 47
                clearButton.Buttons[0].Image = Resource.cancel_16x16;
48
                //clearButton.ButtonClick += repositoryItemButtonEdit_ButtonClick;
48
                clearButton.ButtonClick += repositoryItemButtonEdit_ButtonClick;
49 49
                clearButton.TextEditStyle = TextEditStyles.HideTextEditor;
50 50

  
51 51
                #region Symbol Mapping Setting
......
145 145

  
146 146
        private void btnSave_Click(object sender, EventArgs e)
147 147
        {
148
            ClearImage();
149
            DialogResult = DialogResult.OK;
148
            List<Tuple<string, string, string>> symbolDatas = new List<Tuple<string, string, string>>();
149
            #region Set Datas
150
            DataTable symbolDT = gridControlSymbol.DataSource as DataTable;
151
            foreach (DataRow row in symbolDT.Rows)
152
            {
153
                string uid = row["UID"].ToString();
154
                string name = row["Name"].ToString();
155
                string apidSymbol = row["APID_SYMBOL"].ToString();
156
                symbolDatas.Add(new Tuple<string, string, string>(uid, name, apidSymbol));
157
            }
158
            #endregion
159

  
160
            if (Project_DB.InsertSymbolMapping(symbolDatas))
161
                MessageBox.Show("Save Success!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
162
            else
163
                MessageBox.Show("Save Fail!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
150 164
        }
151 165

  
152 166
        private void btnClose_Click(object sender, EventArgs e)
......
320 334
                    pictureEditMapped.Image = Image.FromFile(_ID2ImagePath);
321 335
            }
322 336
        }
337
        public void repositoryItemButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
338
        {
339
            string value = string.Empty;
340
            if (tabbedControlGroup.SelectedTabPage.Name == "GroupSymbol" && gridViewSymbol.FocusedRowHandle >= 0)
341
                value = gridViewSymbol.GetRowCellDisplayText(gridViewSymbol.FocusedRowHandle, "APID_SYMBOL");
342
            
343
            if (!string.IsNullOrEmpty(value) && 
344
                MessageBox.Show("Are you sure you want to clear mapping information?", "APID Converter", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
345
            {
346
                if (tabbedControlGroup.SelectedTabPage.Name == "GroupSymbol" && gridViewSymbol.FocusedRowHandle >= 0)
347
                    gridViewSymbol.SetRowCellValue(gridViewSymbol.FocusedRowHandle, "APID_SYMBOL", null);
348
            }
349
        }
323 350
        #endregion
324 351

  
325 352
        private void GetNodeLoopText(TreeListNode node, ref string result)

내보내기 Unified diff

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