프로젝트

일반

사용자정보

개정판 1ae1a1c6

ID1ae1a1c6d8b0f2f69e0f12b5d83a9852f1557bbf
상위 51ea098d
하위 0fe04b33

이지연이(가) 3년 이상 전에 추가함

issue #000: db 연결 수정 중

Change-Id: I0cc7e878982d87f838c3cf2a78cea72f8a94faed

차이점 보기:

DTI_PID/ID2PSN/DB.cs
27 27
        const string PSN_VIEW = "T_PSN_VIEW";
28 28
        const string PSN_TOPOLOGYSET = "SPPIDTopologySet";
29 29

  
30
        private static SqlConnection GetSqlConnection()
30
        /// <summary>
31
        ///  ID2 Project.db 데이터를 가져온다. 
32
        ///  DB 접속 정보 및 DBType (Sqlite, Mssql) 정보를 가져옴
33
        ///  - JY
34
        /// </summary>
35
        /// <returns></returns>
36
        public static DataTable GetProject()
31 37
        {
38
            DataTable dt = new DataTable();
39
            ID2Info id2Info = ID2Info.GetInstance();
40
            try
41
            {
42
                using (SQLiteConnection connection = new SQLiteConnection(@"Data Source = C:\ProgramData\Digital PID\Project.db", true))
43
                {
44
                    connection.Open();
45
                    if (connection.State.Equals(ConnectionState.Open))
46
                    {
47
                        using (SQLiteCommand cmd = connection.CreateCommand())
48
                        {
49
                            cmd.CommandText = "SELECT p.[Id], p.Name, p.Path, s.DBTypes_UID, s.Host, s.[User], s.[Password], s.FilePath FROM DBSettings s, Projects p WHERE s.Projects_UID = p.[Id]";
50
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
51
                                dt.Load(dr);
52
                        }
53

  
54
                    }
55
                    connection.Close();
56
                }
57
            }
58
            catch (Exception ex)
59
            {
60
                System.Windows.Forms.MessageBox.Show(ex.Message);
61
            }
62

  
63
            dt.AcceptChanges();
64
            dt.DefaultView.Sort = "Name";
65
            dt = dt.DefaultView.ToTable();
32 66

  
67
            return dt;
68
        }
33 69

  
34
                ID2Info id2Info = ID2Info.GetInstance();
70
        /// <summary>
71
        /// Mssql 연결
72
        /// - JY
73
        /// </summary>
74
        /// <returns></returns>
75
        private static SqlConnection GetSqlConnection()
76
        {
77
            ID2Info id2Info = ID2Info.GetInstance();
35 78
            SqlConnection connection = null;
36 79
            try
37 80
            {
......
56 99
            return connection;
57 100

  
58 101
        }
102

  
103
        /// <summary>
104
        ///  초기 DB 생성
105
        ///  - JY
106
        /// </summary>
107
        /// <returns></returns>
59 108
        public static bool ConnTestAndCreateTable()
60 109
        {
61 110
            bool result = false;
62 111
            ID2Info id2Info = ID2Info.GetInstance();
63
         
64
            if(id2Info.ID2DBType == ID2DB_Type.SQLite)
112

  
113
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
65 114
            {
66 115
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", id2Info.DBFilePath), true))
67 116
                {
......
185 234
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT)", PSN_VIEW);
186 235
                                        cmd.ExecuteNonQuery();
187 236
                                    }
188
                                }                                
237
                                }
189 238
                            }
190 239
                            result = true;
191 240
                        }
......
205 254
            return result;
206 255
        }
207 256

  
208
        public static DataTable SelectHeaderSetting()
257
        // ID2 DB 데이터
258
        public static DataTable SelectOPCRelations()
209 259
        {
210 260
            DataTable dt = new DataTable();
211 261
            ID2Info id2Info = ID2Info.GetInstance();
......
218 268
                        connection.Open();
219 269
                        using (SQLiteCommand cmd = connection.CreateCommand())
220 270
                        {
221
                            cmd.CommandText = string.Format(@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {0};", PSN_HEADER_SETTING);
271
                            cmd.CommandText = "SELECT * FROM OPCRelations;";
222 272
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
223 273
                                dt.Load(dr);
224 274
                        }
......
234 284
                    }
235 285
                }
236 286
            }
237

  
238
            return dt;
239
        }
240

  
241
        public static DataTable SelectVentDrainSetting()
242
        {
243
            DataTable dt = new DataTable();
244
            ID2Info id2Info = ID2Info.GetInstance();
245
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
287
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
246 288
            {
247
                try
289
                using (SqlConnection connection = GetSqlConnection())
248 290
                {
249
                    connection.Open();
250
                    using (SQLiteCommand cmd = connection.CreateCommand())
291
                    try
251 292
                    {
252
                        cmd.CommandText = string.Format(@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {0};", PSN_VENTDRAIN_SETTING);
253
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
254
                            dt.Load(dr);
293
                        if (connection != null && connection.State == ConnectionState.Open)
294
                        {
295
                            using (SqlCommand cmd = connection.CreateCommand())
296
                            {
297
                                cmd.CommandText = "SELECT * FROM OPCRelations;";
298
                                using (SqlDataReader dr = cmd.ExecuteReader())
299
                                    dt.Load(dr);
300
                            }
301
                            connection.Close();
302
                        }
303
                    }
304
                    catch (Exception ex)
305
                    {
306
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
307
                    }
308
                    finally
309
                    {
310
                        if (connection != null)
311
                            connection.Dispose();
255 312
                    }
256
                    connection.Close();
257
                }
258
                catch (Exception ex)
259
                {
260
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
261
                }
262
                finally
263
                {
264
                    connection.Dispose();
265 313
                }
266 314
            }
315

  
267 316
            return dt;
268 317
        }
269 318

  
270
        public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos)
319
        public static DataTable SelectDrawings()
271 320
        {
321
            DataTable dt = new DataTable();
272 322
            ID2Info id2Info = ID2Info.GetInstance();
273
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
323
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
274 324
            {
275
                try
325
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
276 326
                {
277
                    connection.Open();
278
                    using (SQLiteCommand cmd = connection.CreateCommand())
327
                    try
279 328
                    {
280
                        cmd.CommandText = string.Format("DELETE FROM {0}", PSN_HEADER_SETTING);
281
                        cmd.ExecuteNonQuery();
282

  
283
                        foreach (HeaderInfo headerInfo in headerInfos)
329
                        connection.Open();
330
                        using (SQLiteCommand cmd = connection.CreateCommand())
284 331
                        {
285
                            foreach (HeaderItem item in headerInfo.HeaderItems)
286
                            {
287
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)", PSN_HEADER_SETTING);
288
                                cmd.Parameters.Clear();
289
                                cmd.Parameters.AddWithValue("@GROUP_ID", headerInfo.UID);
290
                                cmd.Parameters.AddWithValue("@DESCRIPTION", headerInfo.Description);
291
                                cmd.Parameters.AddWithValue("@INDEX", item.Index);
292
                                cmd.Parameters.AddWithValue("@NAME", item.Name);
293
                                cmd.ExecuteNonQuery();
294
                            }
332
                            cmd.CommandText = "SELECT * FROM Drawings;";
333
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
334
                                dt.Load(dr);
295 335
                        }
336
                        connection.Close();
337
                    }
338
                    catch (Exception ex)
339
                    {
340
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
341
                    }
342
                    finally
343
                    {
344
                        connection.Dispose();
296 345
                    }
297
                    connection.Close();
298
                }
299
                catch (Exception ex)
300
                {
301
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
302
                    return false;
303
                }
304
                finally
305
                {
306
                    connection.Dispose();
307 346
                }
308 347
            }
309
            return true;
310
        }
311

  
312
        public static bool SaveVentDrainSetting(List<VentDrainInfo> ventDrainInfos)
313
        {
314
            ID2Info id2Info = ID2Info.GetInstance();
315
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
348
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
316 349
            {
317
                try
350
                using (SqlConnection connection = GetSqlConnection())
318 351
                {
319
                    connection.Open();
320
                    using (SQLiteCommand cmd = connection.CreateCommand())
352
                    try
321 353
                    {
322
                        cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VENTDRAIN_SETTING);
323
                        cmd.ExecuteNonQuery();
324

  
325
                        foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
354
                        if (connection != null && connection.State == ConnectionState.Open)
326 355
                        {
327
                            foreach (VentDrainItem item in ventDrainInfo.VentDrainItems)
356
                            using (SqlCommand cmd = connection.CreateCommand())
328 357
                            {
329
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)", PSN_VENTDRAIN_SETTING);
330
                                cmd.Parameters.Clear();
331
                                cmd.Parameters.AddWithValue("@GROUP_ID", ventDrainInfo.UID);
332
                                cmd.Parameters.AddWithValue("@DESCRIPTION", ventDrainInfo.Description);
333
                                cmd.Parameters.AddWithValue("@INDEX", item.Index);
334
                                cmd.Parameters.AddWithValue("@NAME", item.Name);
335
                                cmd.ExecuteNonQuery();
358
                                cmd.CommandText = "SELECT * FROM Drawings;";
359
                                using (SqlDataReader dr = cmd.ExecuteReader())
360
                                    dt.Load(dr);
336 361
                            }
362
                            connection.Close();
337 363
                        }
338 364
                    }
339
                    connection.Close();
340
                }
341
                catch (Exception ex)
342
                {
343
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
344
                    return false;
345
                }
346
                finally
347
                {
348
                    connection.Dispose();
365
                    catch (Exception ex)
366
                    {
367
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
368
                    }
369
                    finally
370
                    {
371
                        if (connection != null)
372
                            connection.Dispose();
373
                    }
349 374
                }
350 375
            }
351
            return true;
376

  
377
            return dt;
352 378
        }
353 379

  
354
        public static DataTable SelectOPCRelations()
380
        public static DataTable SelectLineProperties()
355 381
        {
356 382
            DataTable dt = new DataTable();
357 383
            ID2Info id2Info = ID2Info.GetInstance();
358
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
384
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
359 385
            {
360
                try
386
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
361 387
                {
362
                    connection.Open();
363
                    using (SQLiteCommand cmd = connection.CreateCommand())
388
                    try
364 389
                    {
365
                        cmd.CommandText = "SELECT * FROM OPCRelations;";
366
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
367
                            dt.Load(dr);
390
                        connection.Open();
391
                        using (SQLiteCommand cmd = connection.CreateCommand())
392
                        {
393
                            cmd.CommandText = "SELECT * FROM LineProperties;";
394
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
395
                                dt.Load(dr);
396
                        }
397
                        connection.Close();
398
                    }
399
                    catch (Exception ex)
400
                    {
401
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
402
                    }
403
                    finally
404
                    {
405
                        connection.Dispose();
368 406
                    }
369
                    connection.Close();
370
                }
371
                catch (Exception ex)
372
                {
373
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
374 407
                }
375
                finally
408
            }
409
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
410
            {
411
                using (SqlConnection connection = GetSqlConnection())
376 412
                {
377
                    connection.Dispose();
413
                    try
414
                    {
415
                        if (connection != null && connection.State == ConnectionState.Open)
416
                        {
417
                            using (SqlCommand cmd = connection.CreateCommand())
418
                            {
419
                                cmd.CommandText = "SELECT * FROM LineProperties;";
420
                                using (SqlDataReader dr = cmd.ExecuteReader())
421
                                    dt.Load(dr);
422
                            }
423
                            connection.Close();
424
                        }
425
                    }
426
                    catch (Exception ex)
427
                    {
428
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
429
                    }
430
                    finally
431
                    {
432
                        if (connection != null)
433
                            connection.Dispose();
434
                    }
378 435
                }
379 436
            }
380 437
            return dt;
381 438
        }
382

  
383
        public static DataTable SelectDrawings()
439
        
440
        public static DataTable SelectFluidCode()
384 441
        {
385 442
            DataTable dt = new DataTable();
386 443
            ID2Info id2Info = ID2Info.GetInstance();
387
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
444
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
388 445
            {
389
                try
446
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
390 447
                {
391
                    connection.Open();
392
                    using (SQLiteCommand cmd = connection.CreateCommand())
448
                    try
393 449
                    {
394
                        cmd.CommandText = "SELECT * FROM Drawings;";
395
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
396
                            dt.Load(dr);
450
                        connection.Open();
451
                        using (SQLiteCommand cmd = connection.CreateCommand())
452
                        {
453
                            cmd.CommandText = "SELECT * FROM FluidCode;";
454
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
455
                                dt.Load(dr);
456
                        }
457
                        connection.Close();
458
                    }
459
                    catch (Exception ex)
460
                    {
461
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
462
                    }
463
                    finally
464
                    {
465
                        connection.Dispose();
397 466
                    }
398
                    connection.Close();
399 467
                }
400
                catch (Exception ex)
468
            }
469
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
470
            {
471
                using (SqlConnection connection = GetSqlConnection())
401 472
                {
402
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
473
                    try
474
                    {
475
                        if (connection != null && connection.State == ConnectionState.Open)
476
                        {
477
                            using (SqlCommand cmd = connection.CreateCommand())
478
                            {
479
                                cmd.CommandText = "SELECT * FROM FluidCode;";
480
                                using (SqlDataReader dr = cmd.ExecuteReader())
481
                                    dt.Load(dr);
482
                            }
483
                            connection.Close();
484
                        }
485
                    }
486
                    catch (Exception ex)
487
                    {
488
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
489
                    }
490
                    finally
491
                    {
492
                        if (connection != null)
493
                            connection.Dispose();
494
                    }
403 495
                }
404
                finally
496
            }
497

  
498
            return dt;
499
        }
500

  
501
        public static DataTable SelectPipingMaterialsClass()
502
        {
503
            DataTable dt = new DataTable();
504
            ID2Info id2Info = ID2Info.GetInstance();
505
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
506
            {
507
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
405 508
                {
406
                    connection.Dispose();
509
                    try
510
                    {
511
                        connection.Open();
512
                        using (SQLiteCommand cmd = connection.CreateCommand())
513
                        {
514
                            cmd.CommandText = "SELECT * FROM PipingMaterialsClass;";
515
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
516
                                dt.Load(dr);
517
                        }
518
                        connection.Close();
519
                    }
520
                    catch (Exception ex)
521
                    {
522
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
523
                    }
524
                    finally
525
                    {
526
                        connection.Dispose();
527
                    }
528
                }
529
            }
530
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
531
            {
532
                using (SqlConnection connection = GetSqlConnection())
533
                {
534
                    try
535
                    {
536
                        if (connection != null && connection.State == ConnectionState.Open)
537
                        {
538
                            using (SqlCommand cmd = connection.CreateCommand())
539
                            {
540
                                cmd.CommandText = "SELECT * FROM PipingMaterialsClass;";
541
                                using (SqlDataReader dr = cmd.ExecuteReader())
542
                                    dt.Load(dr);
543
                            }
544
                            connection.Close();
545
                        }
546
                    }
547
                    catch (Exception ex)
548
                    {
549
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
550
                    }
551
                    finally
552
                    {
553
                        if (connection != null)
554
                            connection.Dispose();
555
                    }
407 556
                }
408 557
            }
558

  
409 559
            return dt;
410 560
        }
411 561

  
412
        public static DataTable SelectLineProperties()
562
        public static DataTable SelectPSNPIPINGMATLCLASS()
413 563
        {
414 564
            DataTable dt = new DataTable();
415 565
            ID2Info id2Info = ID2Info.GetInstance();
416
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
566
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
417 567
            {
418
                try
568
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
419 569
                {
420
                    connection.Open();
421
                    using (SQLiteCommand cmd = connection.CreateCommand())
570
                    try
422 571
                    {
423
                        cmd.CommandText = "SELECT * FROM LineProperties;";
424
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
425
                            dt.Load(dr);
572
                        connection.Open();
573
                        using (SQLiteCommand cmd = connection.CreateCommand())
574
                        {
575
                            cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PIPINGMATLCLASS);
576
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
577
                                dt.Load(dr);
578
                        }
579
                        connection.Close();
580
                    }
581
                    catch (Exception ex)
582
                    {
583
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
584
                    }
585
                    finally
586
                    {
587
                        connection.Dispose();
426 588
                    }
427
                    connection.Close();
428 589
                }
429
                catch (Exception ex)
590
            }
591
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
592
            {
593
                using (SqlConnection connection = GetSqlConnection())
430 594
                {
431
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
595
                    try
596
                    {
597
                        if (connection != null && connection.State == ConnectionState.Open)
598
                        {
599
                            using (SqlCommand cmd = connection.CreateCommand())
600
                            {
601
                                cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PIPINGMATLCLASS);
602
                                using (SqlDataReader dr = cmd.ExecuteReader())
603
                                    dt.Load(dr);
604
                            }
605
                            connection.Close();
606
                        }
607
                    }
608
                    catch (Exception ex)
609
                    {
610
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
611
                    }
612
                    finally
613
                    {
614
                        if (connection != null)
615
                            connection.Dispose();
616
                    }
432 617
                }
433
                finally
618
            }
619

  
620
            return dt;
621
        }
622

  
623
        public static DataTable SelectNominalDiameter()
624
        {
625
            DataTable dt = new DataTable();
626
            ID2Info id2Info = ID2Info.GetInstance();
627
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
628
            {
629
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
434 630
                {
435
                    connection.Dispose();
631
                    try
632
                    {
633
                        connection.Open();
634
                        using (SQLiteCommand cmd = connection.CreateCommand())
635
                        {
636
                            cmd.CommandText = "SELECT * FROM NominalDiameter ORDER BY Metric DESC;";
637
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
638
                                dt.Load(dr);
639
                        }
640
                        connection.Close();
641
                    }
642
                    catch (Exception ex)
643
                    {
644
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
645
                    }
646
                    finally
647
                    {
648
                        connection.Dispose();
649
                    }
436 650
                }
437 651
            }
652
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
653
            {
654
                using (SqlConnection connection = GetSqlConnection())
655
                {
656
                    try
657
                    {
658
                        if (connection != null && connection.State == ConnectionState.Open)
659
                        {
660
                            using (SqlCommand cmd = connection.CreateCommand())
661
                            {
662
                                cmd.CommandText = "SELECT * FROM NominalDiameter ORDER BY Metric DESC;";
663
                                using (SqlDataReader dr = cmd.ExecuteReader())
664
                                    dt.Load(dr);
665
                            }
666
                            connection.Close();
667
                        }
668
                    }
669
                    catch (Exception ex)
670
                    {
671
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
672
                    }
673
                    finally
674
                    {
675
                        if (connection != null)
676
                            connection.Dispose();
677
                    }
678
                }
679
            }
680

  
681
            dt.Rows.RemoveAt(0);
682
            dt.Rows.RemoveAt(0);
683
            dt.Rows.RemoveAt(0);
684
            dt.Rows.RemoveAt(0);
685

  
438 686
            return dt;
439 687
        }
440 688

  
441
        public static DataTable SelectTopologyRule()
689
        public static DataTable SelectSymbolAttribute()
442 690
        {
443 691
            DataTable dt = new DataTable();
444 692
            ID2Info id2Info = ID2Info.GetInstance();
445
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
693
            if(id2Info.ID2DBType == ID2DB_Type.SQLite)
446 694
            {
447
                try
695
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
448 696
                {
449
                    connection.Open();
450
                    using (SQLiteCommand cmd = connection.CreateCommand())
697
                    try
698
                    {
699
                        connection.Open();
700
                        using (SQLiteCommand cmd = connection.CreateCommand())
701
                        {
702
                            cmd.CommandText = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;";
703
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
704
                                dt.Load(dr);
705
                        }
706
                        connection.Close();
707
                    }
708
                    catch (Exception ex)
709
                    {
710
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
711
                    }
712
                    finally
713
                    {
714
                        connection.Dispose();
715
                    }
716
                }
717
            }
718
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
719
            {
720
                using (SqlConnection connection = GetSqlConnection())
721
                {
722
                    try
723
                    {
724
                        if (connection != null && connection.State == ConnectionState.Open)
725
                        {
726
                            using (SqlCommand cmd = connection.CreateCommand())
727
                            {
728
                                cmd.CommandText = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;";
729
                                using (SqlDataReader dr = cmd.ExecuteReader())
730
                                    dt.Load(dr);
731
                            }
732
                            connection.Close();
733
                        }
734
                    }
735
                    catch (Exception ex)
736
                    {
737
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
738
                    }
739
                    finally
740
                    {
741
                        if (connection != null)
742
                            connection.Dispose();
743
                    }
744
                }
745
            }
746
            return dt;
747
        }
748

  
749
        public static DataTable SelectSymbolName()
750
        {
751
            DataTable dt = new DataTable();
752
            ID2Info id2Info = ID2Info.GetInstance();
753
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
754
            {
755
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
756
                {
757
                    try
758
                    {
759
                        connection.Open();
760
                        using (SQLiteCommand cmd = connection.CreateCommand())
761
                        {
762
                            cmd.CommandText = "SELECT * FROM SymbolName;";
763
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
764
                                dt.Load(dr);
765
                        }
766
                        connection.Close();
767
                    }
768
                    catch (Exception ex)
769
                    {
770
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
771
                    }
772
                    finally
773
                    {
774
                        connection.Dispose();
775
                    }
776
                }
777
            }
778
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
779
            {
780
                using (SqlConnection connection = GetSqlConnection())
781
                {
782
                    try
783
                    {
784
                        if (connection != null && connection.State == ConnectionState.Open)
785
                        {
786
                            using (SqlCommand cmd = connection.CreateCommand())
787
                            {
788
                                cmd.CommandText = "SELECT * FROM SymbolName;";
789
                                using (SqlDataReader dr = cmd.ExecuteReader())
790
                                    dt.Load(dr);
791
                            }
792
                            connection.Close();
793
                        }
794
                    }
795
                    catch (Exception ex)
796
                    {
797
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
798
                    }
799
                    finally
800
                    {
801
                        if (connection != null)
802
                            connection.Dispose();
803
                    }
804
                }
805
            }
806
            return dt;
807
        }              
808

  
809
        public static double[] GetDrawingSize()
810
        {
811
            double[] result = null;
812

  
813
            DataTable dt = new DataTable();
814
            ID2Info id2Info = ID2Info.GetInstance();
815
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
816
            {
817
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
818
                {
819
                    try
820
                    {
821
                        connection.Open();
822
                        using (SQLiteCommand cmd = connection.CreateCommand())
823
                        {
824
                            cmd.CommandText = "SELECT value FROM Configuration WHERE Section = 'Area' AND Key = 'Drawing';";
825
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
826
                                dt.Load(dr);
827

  
828
                            if (dt.Rows.Count == 1)
829
                            {
830
                                string value = dt.Rows[0][0].ToString();
831
                                string[] split = value.Split(new char[] { ',' });
832
                                result = new double[] {
833
                                Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", "")),
834
                                Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", "")),
835
                                Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", "")),
836
                                Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", ""))
837
                                };
838
                                result = new double[] {
839
                                Math.Min(result[0], result[2]),
840
                                Math.Min(result[1], result[3]),
841
                                Math.Max(result[0], result[2]),
842
                                Math.Max(result[1], result[3])
843
                                };
844
                            }
845
                        }
846
                        connection.Close();
847
                    }
848
                    catch (Exception ex)
849
                    {
850
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
851
                    }
852
                    finally
853
                    {
854
                        connection.Dispose();
855
                    }
856
                }
857
            }
858
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
859
            {
860
                using (SqlConnection connection = GetSqlConnection())
861
                {
862
                    try
863
                    {
864
                        if (connection != null && connection.State == ConnectionState.Open)
865
                        {
866
                            using (SqlCommand cmd = connection.CreateCommand())
867
                            {
868
                                cmd.CommandText = "SELECT value FROM Configuration WHERE Section = 'Area' AND Key = 'Drawing';";
869
                                using (SqlDataReader dr = cmd.ExecuteReader())
870
                                    dt.Load(dr);
871

  
872
                                if (dt.Rows.Count == 1)
873
                                {
874
                                    string value = dt.Rows[0][0].ToString();
875
                                    string[] split = value.Split(new char[] { ',' });
876
                                    result = new double[] {
877
                                    Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", "")),
878
                                    Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", "")),
879
                                    Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", "")),
880
                                    Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", ""))
881
                                    };
882
                                    result = new double[] {
883
                                    Math.Min(result[0], result[2]),
884
                                    Math.Min(result[1], result[3]),
885
                                    Math.Max(result[0], result[2]),
886
                                    Math.Max(result[1], result[3])
887
                                    };
888
                                }
889
                            }
890
                            connection.Close();
891
                        }
892
                    }
893
                    catch (Exception ex)
894
                    {
895
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
896
                    }
897
                    finally
898
                    {
899
                        if (connection != null)
900
                            connection.Dispose();
901
                    }
902
                }
903
            }
904

  
905
            return result;
906
        }
907

  
908
        public static DataTable GetEquipmentType()
909
        {
910
            DataTable dt = new DataTable();
911
            ID2Info id2Info = ID2Info.GetInstance();
912
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
913
            {
914
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
915
                {
916
                    try
917
                    {
918
                        connection.Open();
919
                        using (SQLiteCommand cmd = connection.CreateCommand())
920
                        {
921
                            cmd.CommandText = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';";
922
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
923
                                dt.Load(dr);
924
                        }
925
                        connection.Close();
926
                    }
927
                    catch (Exception ex)
928
                    {
929
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
930
                    }
931
                    finally
932
                    {
933
                        connection.Dispose();
934
                    }
935
                }
936
            }
937
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
938
            {
939
                using (SqlConnection connection = GetSqlConnection())
940
                {
941
                    try
942
                    {
943
                        if (connection != null && connection.State == ConnectionState.Open)
944
                        {
945
                            using (SqlCommand cmd = connection.CreateCommand())
946
                            {
947
                                cmd.CommandText = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';";
948
                                using (SqlDataReader dr = cmd.ExecuteReader())
949
                                    dt.Load(dr);
950
                            }
951
                            connection.Close();
952
                        }
953
                    }
954
                    catch (Exception ex)
955
                    {
956
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
957
                    }
958
                    finally
451 959
                    {
452
                        cmd.CommandText = string.Format(@"SELECT * FROM {0};", PSN_TOPOLOGY_RULE);
453
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
454
                            dt.Load(dr);
960
                        if (connection != null)
961
                            connection.Dispose();
455 962
                    }
456
                    connection.Close();
457
                }
458
                catch (Exception ex)
459
                {
460
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
461
                }
462
                finally
463
                {
464
                    connection.Dispose();
465 963
                }
466 964
            }
467 965
            return dt;
468 966
        }
469 967

  
470
        public static bool SaveTopologyRule(DataTable dt)
968
        /// <summary>
969
        ///  Zoom 을 위하여 저장 T_PSN_VIEW 데이터로 PSN 데이터지만 Msqql 과 Sqlite 둘다 저장되어 있음
970
        ///  => ID2 가 DB 타입에 따라서 바라보는 DB가 mssql이냐 sqlite냐로 지정되기 때문에 zoom 기능을 그대로 사용하려면 해당 데이터는 psn도 id2 dbtype에 맞춰서 저장 및 로드해야함
971
        /// </summary>
972
        /// <param name="values"></param>
973
        /// <returns></returns>
974
        public static bool SaveView(List<string> values)
471 975
        {
472 976
            ID2Info id2Info = ID2Info.GetInstance();
473
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
977

  
978
            bool result = true;
979

  
980
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
474 981
            {
475
                try
982
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
476 983
                {
477
                    connection.Open();
478
                    using (SQLiteCommand cmd = connection.CreateCommand())
984
                    try
479 985
                    {
480
                        cmd.CommandText = string.Format("DELETE FROM {0}", PSN_TOPOLOGY_RULE);
481
                        cmd.ExecuteNonQuery();
986
                        connection.Open();
482 987

  
483
                        foreach (DataRow row in dt.Rows)
988
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
484 989
                        {
485
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID)", PSN_TOPOLOGY_RULE);
486
                            cmd.Parameters.Clear();
487
                            cmd.Parameters.AddWithValue("@UID", row["NAME"].ToString());
488
                            cmd.ExecuteNonQuery();
990
                            try
991
                            {
992
                                using (SQLiteCommand cmd = connection.CreateCommand())
993
                                {
994
                                    cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VIEW);
995
                                    cmd.ExecuteNonQuery();
996

  
997
                                    foreach (string value in values)
998
                                    {
999
                                        cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID)", PSN_VIEW);
1000
                                        cmd.Parameters.Clear();
1001
                                        cmd.Parameters.AddWithValue("@OID", value);
1002
                                        cmd.ExecuteNonQuery();
1003
                                    }
1004
                                }
1005
                                transaction.Commit();
1006
                                connection.Close();
1007
                            }
1008
                            catch (Exception ex)
1009
                            {
1010
                                transaction.Rollback();
1011
                                result = false;
1012
                            }
1013
                            finally
1014
                            {
1015
                                transaction.Dispose();
1016
                            }
489 1017
                        }
490 1018
                    }
491
                    connection.Close();
492
                }
493
                catch (Exception ex)
494
                {
495
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
496
                    return false;
1019
                    catch (Exception ex)
1020
                    {
1021
                        System.Windows.Forms.MessageBox.Show(ex.Message);
1022
                        result = false;
1023
                    }
1024
                    finally
1025
                    {
1026
                        connection.Dispose();
1027
                    }
497 1028
                }
498
                finally
1029
            }
1030
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
1031
            {
1032
                using (SqlConnection connection = GetSqlConnection())
499 1033
                {
500
                    connection.Dispose();
1034
                    try
1035
                    {
1036
                        if (connection != null && connection.State == ConnectionState.Open)
1037
                        {
1038
                            using (SqlCommand cmd = connection.CreateCommand())
1039
                            {
1040
                                cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VIEW);
1041
                                cmd.ExecuteNonQuery();
1042

  
1043
                                foreach (string value in values)
1044
                                {
1045
                                    cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID)", PSN_VIEW);
1046
                                    cmd.Parameters.Clear();
1047
                                    cmd.Parameters.AddWithValue("@OID", value);
1048
                                    cmd.ExecuteNonQuery();
1049
                                }
1050
                            }
1051
                            connection.Close();
1052
                        }
1053
                        else
1054
                        {
1055
                            return false;
1056
                        }
1057
                    }
1058
                    catch (Exception ex)
1059
                    {
1060
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1061
                        return false;
1062
                    }
1063
                    finally
1064
                    {
1065
                        if (connection != null)
1066
                            connection.Dispose();
1067
                    }
501 1068
                }
502 1069
            }
503
            return true;
1070
            return result;
504 1071
        }
505 1072

  
506
        public static DataTable SelectFluidCode()
1073
        public static bool DeleteView()
507 1074
        {
508
            DataTable dt = new DataTable();
509 1075
            ID2Info id2Info = ID2Info.GetInstance();
510
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
1076

  
1077
            bool result = true;
1078
            if (id2Info.ID2DBType == ID2DB_Type.SQLite)
511 1079
            {
512
                try
1080
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
513 1081
                {
514
                    connection.Open();
515
                    using (SQLiteCommand cmd = connection.CreateCommand())
1082
                    try
516 1083
                    {
517
                        cmd.CommandText = "SELECT * FROM FluidCode;";
518
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
519
                            dt.Load(dr);
1084
                        connection.Open();
1085

  
1086
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1087
                        {
1088
                            try
1089
                            {
1090
                                using (SQLiteCommand cmd = connection.CreateCommand())
1091
                                {
1092
                                    cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VIEW);
1093
                                    cmd.ExecuteNonQuery();
1094
                                }
1095
                                transaction.Commit();
1096
                                connection.Close();
1097
                            }
1098
                            catch (Exception ex)
1099
                            {
1100
                                transaction.Rollback();
1101
                                result = false;
1102
                            }
1103
                            finally
1104
                            {
1105
                                transaction.Dispose();
1106
                            }
1107
                        }
1108
                    }
1109
                    catch (Exception ex)
1110
                    {
1111
                        System.Windows.Forms.MessageBox.Show(ex.Message);
1112
                        result = false;
1113
                    }
1114
                    finally
1115
                    {
1116
                        connection.Dispose();
520 1117
                    }
521
                    connection.Close();
522
                }
523
                catch (Exception ex)
524
                {
525
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
526 1118
                }
527
                finally
1119
            }
1120
            else if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
1121
            {
1122
                using (SqlConnection connection = GetSqlConnection())
528 1123
                {
529
                    connection.Dispose();
1124
                    try
1125
                    {
1126
                        if (connection != null && connection.State == ConnectionState.Open)
1127
                        {
1128
                            using (SqlCommand cmd = connection.CreateCommand())
1129
                            {
1130
                                cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VIEW);
1131
                                cmd.ExecuteNonQuery();
1132
                            }
1133
                            connection.Close();
1134
                        }
1135
                        else
1136
                        {
1137
                            return false;
1138
                        }
1139
                    }
1140
                    catch (Exception ex)
1141
                    {
1142
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1143
                        return false;
1144
                    }
1145
                    finally
1146
                    {
1147
                        if (connection != null)
1148
                            connection.Dispose();
1149
                    }
530 1150
                }
531 1151
            }
532
            return dt;
1152

  
1153

  
1154
            return result;
533 1155
        }
534 1156

  
535
        public static DataTable SelectPipingMaterialsClass()
1157
        //PSN Sqlite 
1158
        public static DataTable SelectHeaderSetting()
536 1159
        {
537 1160
            DataTable dt = new DataTable();
538 1161
            ID2Info id2Info = ID2Info.GetInstance();
1162

  
539 1163
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
540 1164
            {
541 1165
                try
......
543 1167
                    connection.Open();
544 1168
                    using (SQLiteCommand cmd = connection.CreateCommand())
545 1169
                    {
546
                        cmd.CommandText = "SELECT * FROM PipingMaterialsClass;";
1170
                        cmd.CommandText = string.Format(@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {0};", PSN_HEADER_SETTING);
547 1171
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
548 1172
                            dt.Load(dr);
549 1173
                    }
......
558 1182
                    connection.Dispose();
559 1183
                }
560 1184
            }
1185

  
561 1186
            return dt;
562 1187
        }
563 1188

  
564
        public static DataTable SelectPSNFluidCode()
1189
        public static DataTable SelectVentDrainSetting()
565 1190
        {
566 1191
            DataTable dt = new DataTable();
567 1192
            ID2Info id2Info = ID2Info.GetInstance();
......
572 1197
                    connection.Open();
573 1198
                    using (SQLiteCommand cmd = connection.CreateCommand())
574 1199
                    {
575
                        cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_FLUIDCODE);
1200
                        cmd.CommandText = string.Format(@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {0};", PSN_VENTDRAIN_SETTING);
576 1201
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
577 1202
                            dt.Load(dr);
578 1203
                    }
......
590 1215
            return dt;
591 1216
        }
592 1217

  
593
        public static DataTable SelectPSNPIPINGMATLCLASS()
1218
        public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos)
594 1219
        {
595
            DataTable dt = new DataTable();
596 1220
            ID2Info id2Info = ID2Info.GetInstance();
597 1221
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
598 1222
            {
......
601 1225
                    connection.Open();
602 1226
                    using (SQLiteCommand cmd = connection.CreateCommand())
603 1227
                    {
604
                        cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PIPINGMATLCLASS);
605
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
606
                            dt.Load(dr);
1228
                        cmd.CommandText = string.Format("DELETE FROM {0}", PSN_HEADER_SETTING);
1229
                        cmd.ExecuteNonQuery();
1230

  
1231
                        foreach (HeaderInfo headerInfo in headerInfos)
1232
                        {
1233
                            foreach (HeaderItem item in headerInfo.HeaderItems)
1234
                            {
1235
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)", PSN_HEADER_SETTING);
1236
                                cmd.Parameters.Clear();
1237
                                cmd.Parameters.AddWithValue("@GROUP_ID", headerInfo.UID);
1238
                                cmd.Parameters.AddWithValue("@DESCRIPTION", headerInfo.Description);
1239
                                cmd.Parameters.AddWithValue("@INDEX", item.Index);
1240
                                cmd.Parameters.AddWithValue("@NAME", item.Name);
1241
                                cmd.ExecuteNonQuery();
1242
                            }
1243
                        }
607 1244
                    }
608 1245
                    connection.Close();
609 1246
                }
610 1247
                catch (Exception ex)
611 1248
                {
612 1249
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1250
                    return false;
613 1251
                }
614 1252
                finally
615 1253
                {
616 1254
                    connection.Dispose();
617 1255
                }
618 1256
            }
619
            return dt;
1257
            return true;
620 1258
        }
621 1259

  
622
        public static DataTable SelectNominalDiameter()
1260
        public static bool SaveVentDrainSetting(List<VentDrainInfo> ventDrainInfos)
623 1261
        {
624
            DataTable dt = new DataTable();
625 1262
            ID2Info id2Info = ID2Info.GetInstance();
626 1263
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
627 1264
            {
......
630 1267
                    connection.Open();
631 1268
                    using (SQLiteCommand cmd = connection.CreateCommand())
632 1269
                    {
633
                        cmd.CommandText = "SELECT * FROM NominalDiameter ORDER BY Metric DESC;";
634
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
635
                            dt.Load(dr);
1270
                        cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VENTDRAIN_SETTING);
1271
                        cmd.ExecuteNonQuery();
1272

  
1273
                        foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
1274
                        {
1275
                            foreach (VentDrainItem item in ventDrainInfo.VentDrainItems)
1276
                            {
1277
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)", PSN_VENTDRAIN_SETTING);
1278
                                cmd.Parameters.Clear();
1279
                                cmd.Parameters.AddWithValue("@GROUP_ID", ventDrainInfo.UID);
1280
                                cmd.Parameters.AddWithValue("@DESCRIPTION", ventDrainInfo.Description);
1281
                                cmd.Parameters.AddWithValue("@INDEX", item.Index);
1282
                                cmd.Parameters.AddWithValue("@NAME", item.Name);
1283
                                cmd.ExecuteNonQuery();
1284
                            }
1285
                        }
636 1286
                    }
637 1287
                    connection.Close();
638 1288
                }
639 1289
                catch (Exception ex)
640 1290
                {
641 1291
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1292
                    return false;
642 1293
                }
643 1294
                finally
644 1295
                {
645 1296
                    connection.Dispose();
646 1297
                }
647 1298
            }
648

  
649
            dt.Rows.RemoveAt(0);
650
            dt.Rows.RemoveAt(0);
651
            dt.Rows.RemoveAt(0);
652
            dt.Rows.RemoveAt(0);
653

  
654
            return dt;
1299
            return true;
655 1300
        }
656 1301

  
657
        public static DataTable SelectSymbolAttribute()
1302
        public static bool SaveTopologyRule(DataTable dt)
658 1303
        {
659
            DataTable dt = new DataTable();
660 1304
            ID2Info id2Info = ID2Info.GetInstance();
661 1305
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
662 1306
            {
......
665 1309
                    connection.Open();
666 1310
                    using (SQLiteCommand cmd = connection.CreateCommand())
667 1311
                    {
668
                        cmd.CommandText = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;";
669
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
670
                            dt.Load(dr);
1312
                        cmd.CommandText = string.Format("DELETE FROM {0}", PSN_TOPOLOGY_RULE);
1313
                        cmd.ExecuteNonQuery();
1314

  
1315
                        foreach (DataRow row in dt.Rows)
1316
                        {
1317
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID)", PSN_TOPOLOGY_RULE);
1318
                            cmd.Parameters.Clear();
1319
                            cmd.Parameters.AddWithValue("@UID", row["NAME"].ToString());
1320
                            cmd.ExecuteNonQuery();
1321
                        }
671 1322
                    }
672 1323
                    connection.Close();
673 1324
                }
674 1325
                catch (Exception ex)
675 1326
                {
676 1327
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1328
                    return false;
677 1329
                }
678 1330
                finally
679 1331
                {
680 1332
                    connection.Dispose();
681 1333
                }
682 1334
            }
683
            return dt;
1335
            return true;
684 1336
        }
685 1337

  
686
        public static DataTable SelectSymbolName()
1338
        public static DataTable SelectTopologyRule()
687 1339
        {
688 1340
            DataTable dt = new DataTable();
689 1341
            ID2Info id2Info = ID2Info.GetInstance();
......
694 1346
                    connection.Open();
695 1347
                    using (SQLiteCommand cmd = connection.CreateCommand())
696 1348
                    {
697
                        cmd.CommandText = "SELECT * FROM SymbolName;";
1349
                        cmd.CommandText = string.Format(@"SELECT * FROM {0};", PSN_TOPOLOGY_RULE);
698 1350
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
699 1351
                            dt.Load(dr);
700 1352
                    }
......
711 1363
            }
712 1364
            return dt;
713 1365
        }
714

  
1366
               
715 1367
        public static bool SavePSNData(PSN item)
716 1368
        {
717 1369
            ID2Info id2Info = ID2Info.GetInstance();
......
873 1525
            ID2Info id2Info = ID2Info.GetInstance();
874 1526

  
875 1527
            bool result = true;
876
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
877
            {
878
                try
879
                {
880
                    connection.Open();
881

  
882
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
883
                    {
884
                        try
885
                        {
886
                            using (SQLiteCommand cmd = connection.CreateCommand())
887
                            {
888
                                cmd.CommandText = string.Format("DELETE FROM {0}", PSN_FLUIDCODE);
889
                                cmd.ExecuteNonQuery();
890

  
891
                                foreach (DataRow row in dt.Rows)
892
                                {
893
                                    cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)", PSN_FLUIDCODE);
894
                                    cmd.Parameters.Clear();
895
                                    cmd.Parameters.AddWithValue("@UID", row["UID"].ToString());
896
                                    cmd.Parameters.AddWithValue("@Code", row["Code"].ToString());
897
                                    cmd.Parameters.AddWithValue("@Description", row["Description"].ToString());
898
                                    cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString());
899
                                    cmd.Parameters.AddWithValue("@Remarks", row["Remarks"].ToString());
900
                                    cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString());
901
                                    cmd.ExecuteNonQuery();
902
                                }
903
                            }
904
                            transaction.Commit();
905
                            connection.Close();
906
                        }
907
                        catch (Exception ex)
908
                        {
909
                            transaction.Rollback();
910
                            result = false;
911
                        }
912
                        finally
913
                        {
914
                            transaction.Dispose();
915
                        }
916
                    }
917
                }
918
                catch (Exception ex)
919
                {
920
                    System.Windows.Forms.MessageBox.Show(ex.Message);
921
                    result = false;
922
                }
923
                finally
924
                {
925
                    connection.Dispose();
926
                }
927
            }
928

  
929
            return result;
930
        }
931

  
932
        public static bool SavePSNPMC(DataTable dt)
933
        {
934
            ID2Info id2Info = ID2Info.GetInstance();
935

  
936
            bool result = true;
937
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true))
938
            {
939
                try
940
                {
941
                    connection.Open();
942

  
943
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
944
                    {
945
                        try
946
                        {
947
                            using (SQLiteCommand cmd = connection.CreateCommand())
948
                            {
949
                                cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PIPINGMATLCLASS);
950
                                cmd.ExecuteNonQuery();
951

  
952
                                foreach (DataRow row in dt.Rows)
953
                                {
954
                                    cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)", PSN_PIPINGMATLCLASS);
955
                                    cmd.Parameters.Clear();
956
                                    cmd.Parameters.AddWithValue("@UID", row["UID"].ToString());
957
                                    cmd.Parameters.AddWithValue("@Priority", row["Priority"].ToString());
958
                                    cmd.Parameters.AddWithValue("@Code", row["Code"].ToString());
959
                                    cmd.Parameters.AddWithValue("@Description", row["Description"].ToString());
960
                                    cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString());
961
                                    cmd.Parameters.AddWithValue("@Remarks", row["Remarks"].ToString());
962
                                    cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString());
963
                                    cmd.ExecuteNonQuery();
964
                                }
965
                            }
966
                            transaction.Commit();
967
                            connection.Close();
968
                        }
969
                        catch (Exception ex)
970
                        {
971
                            transaction.Rollback();
972
                            result = false;
973
                        }
974
                        finally
975
                        {
976
                            transaction.Dispose();
977
                        }
978
                    }
979
                }
980
                catch (Exception ex)
981
                {
982
                    System.Windows.Forms.MessageBox.Show(ex.Message);
983
                    result = false;
984
                }
985
                finally
986
                {
987
                    connection.Dispose();
988
                }
... 이 차이점은 표시할 수 있는 최대 줄수를 초과해서 이 차이점은 잘렸습니다.

내보내기 Unified diff

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