프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / DB / Project_DB.cs @ 69b7387a

이력 | 보기 | 이력해설 | 다운로드 (28 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Globalization;
7
using System.Data.SQLite;
8
using System.Data;
9

    
10
namespace Converter.BaseModel
11
{
12
    public class Project_DB
13
    {
14
        const string SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO";
15
        const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING";
16
        const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING";
17
        const string SPPID_SETTING_TABLE = "T_SPPID_SETTING_TABLE";
18
        const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO";
19

    
20
        const string LineProperties_TABLE = "LineProperties";
21
        const string LineTypes_TABLE = "LineTypes";
22
        const string SymbolType_TABLE = "SymbolType";
23
        const string SymbolAttribute_TABLE = "SymbolAttribute";
24
        const string Symbol_TABLE = "Symbol";
25

    
26
        public static bool ConnTestAndCreateTable()
27
        {
28
            bool result = false;
29
            Project_Info projectInfo = Project_Info.GetInstance();
30
            SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath));
31
            try
32
            {
33
                connection.Open();
34
                if (connection.State == ConnectionState.Open)
35
                {
36
                    CreateTable(connection);
37
                    result = true;
38
                }
39
                connection.Close();
40
            }
41
            catch (Exception ex)
42
            {
43

    
44
            }
45
            finally
46
            {
47
                connection.Dispose();
48
            }
49

    
50
            return result;
51
        }
52

    
53
        public static bool SaveSPPID_DB_INFO(string jsonString)
54
        {
55
            Project_Info projectInfo = Project_Info.GetInstance();
56
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
57
            {
58

    
59
                try
60
                {
61
                    connection.Open();
62
                    using (SQLiteCommand cmd = connection.CreateCommand())
63
                    {
64
                        cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
65
                        cmd.ExecuteNonQuery();
66

    
67
                        cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
68
                        cmd.Parameters.AddWithValue("@jsonString", jsonString);
69
                        cmd.ExecuteNonQuery();
70
                    }
71
                    connection.Close();
72
                }
73
                catch (Exception ex)
74
                {
75
                    return false;
76
                }
77
                finally
78
                {
79
                    connection.Dispose();
80
                }
81
            }
82

    
83
            return true;
84
        }
85

    
86
        public static DataTable SelectSPPID_DB_INFO()
87
        {
88
            DataTable dt = new DataTable();
89
            Project_Info projectInfo = Project_Info.GetInstance();
90
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
91
            {
92
                try
93
                {
94
                    connection.Open();
95
                    using (SQLiteCommand cmd = connection.CreateCommand())
96
                    {
97
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
98
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
99
                            dt.Load(dr);
100
                    }
101
                    connection.Close();
102
                }
103
                catch (Exception ex)
104
                {
105

    
106
                }
107
                finally
108
                {
109
                    connection.Dispose();
110
                }
111
            }
112

    
113
            return dt;
114
        }
115

    
116
        public static bool SaveETCSetting(Dictionary<string,string> dicSetting)
117
        {
118
            Project_Info projectInfo = Project_Info.GetInstance();
119
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
120
            {
121

    
122
                try
123
                {
124
                    connection.Open();
125
                    using (SQLiteCommand cmd = connection.CreateCommand())
126
                    {
127
                        cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
128
                        cmd.ExecuteNonQuery();
129

    
130
                        foreach (var item in dicSetting)
131
                        {
132
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
133
                            cmd.Parameters.AddWithValue("@jsonString", item.Value);
134
                            cmd.Parameters.AddWithValue("@SettingType", item.Key);
135
                            cmd.ExecuteNonQuery();
136
                        }
137
                    }
138
                    connection.Close();
139
                }
140
                catch (Exception ex)
141
                {
142
                    return false;
143
                }
144
                finally
145
                {
146
                    connection.Dispose();
147
                }
148
            }
149

    
150
            return true;
151
        }
152

    
153
        public static DataTable SelectSetting()
154
        {
155
            DataTable dt = new DataTable();
156
            Project_Info projectInfo = Project_Info.GetInstance();
157
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
158
            {
159
                try
160
                {
161
                    connection.Open();
162
                    using (SQLiteCommand cmd = connection.CreateCommand())
163
                    {
164
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
165
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
166
                            dt.Load(dr);
167
                    }
168
                    connection.Close();
169
                }
170
                catch (Exception ex)
171
                {
172

    
173
                }
174
                finally
175
                {
176
                    connection.Dispose();
177
                }
178
            }
179

    
180
            return dt;
181
        }
182

    
183
        private static void CreateTable(SQLiteConnection connection)
184
        {
185
            using (SQLiteCommand cmd = connection.CreateCommand())
186
            {
187
                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
188
                using (SQLiteDataReader dr = cmd.ExecuteReader())
189
                using (DataTable dt = new DataTable())
190
                {
191
                    dt.Load(dr);
192

    
193
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
194
                    {
195
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
196
                        cmd.ExecuteNonQuery();
197
                    }
198
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
199
                    {
200
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE);
201
                        cmd.ExecuteNonQuery();
202
                    }
203
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
204
                    {
205
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE);
206
                        cmd.ExecuteNonQuery();
207
                    }
208
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
209
                    {
210
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
211
                        cmd.ExecuteNonQuery();
212
                    }
213
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
214
                    {
215
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE);
216
                        cmd.ExecuteNonQuery();
217
                    }
218
                }
219

    
220
                #region Check Column 업데이트시 예비용
221
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
222
                using (SQLiteDataReader dr = cmd.ExecuteReader())
223
                using (DataTable dt = new DataTable())
224
                {
225
                    dt.Load(dr);
226
                    if (!dt.Columns.Contains("LEADERLINE"))
227
                    {
228
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE);
229
                        cmd.ExecuteNonQuery();
230
                    }
231
                }
232

    
233
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
234
                using (SQLiteDataReader dr = cmd.ExecuteReader())
235
                using (DataTable dt = new DataTable())
236
                {
237
                    dt.Load(dr);
238
                    if (!dt.Columns.Contains("SettingType"))
239
                    {
240
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE);
241
                        cmd.ExecuteNonQuery();
242
                    }
243
                }
244
                #endregion
245
            }
246
        }
247

    
248
        public static DataTable SelectProjectSymbol()
249
        {
250
            DataTable dt = new DataTable();
251
            Project_Info projectInfo = Project_Info.GetInstance();
252
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
253
            {
254
                try
255
                {
256
                    connection.Open();
257
                    using (SQLiteCommand cmd = connection.CreateCommand())
258
                    {
259
                        cmd.CommandText = string.Format(@"
260
                            SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s 
261
                                LEFT OUTER JOIN {2} as sp 
262
                                    ON s.UID = SP.UID 
263
                            WHERE s.SymbolType_UID = st.UID 
264
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
265
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
266
                            dt.Load(dr);
267

    
268
                        DataTable dtClone = dt.Clone();
269
                        dtClone.Columns["UID"].DataType = typeof(string);
270
                        foreach (DataRow row in dt.Rows)
271
                        {
272
                            dtClone.ImportRow(row);
273
                        }
274
                        dt.Dispose();
275
                        dt = dtClone;
276
                    }
277
                    connection.Close();
278
                }
279
                catch (Exception ex)
280
                {
281

    
282
                }
283
                finally
284
                {
285
                    connection.Dispose();
286
                }
287
            }
288

    
289
            return dt;
290
        }
291

    
292
        public static DataTable SelectProjectChildSymbol()
293
        {
294
            DataTable result = new DataTable();
295
            result.Columns.Add("UID");
296
            result.Columns.Add("Name");
297
            result.Columns.Add("Type");
298
            result.Columns.Add("SPPID_SYMBOL_PATH");
299
            
300
            Project_Info projectInfo = Project_Info.GetInstance();
301
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
302
            using (DataTable dt = new DataTable())
303
            {
304
                try
305
                {
306
                    connection.Open();
307
                    using (SQLiteCommand cmd = connection.CreateCommand())
308
                    {
309
                        cmd.CommandText = string.Format(@"
310
                            SELECT AdditionalSymbol FROM Symbol");
311
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
312
                            dt.Load(dr);
313
                        List<string> childList = new List<string>();
314
                        foreach (DataRow row in dt.Rows)
315
                        {
316
                            if (!string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
317
                            {
318
                                string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
319
                                foreach (var childString in array)
320
                                {
321
                                    childList.Add(childString.Split(new char[] { ',' })[2]);
322
                                }
323
                            }
324

    
325
                        }
326

    
327
                        dt.Clear();
328
                        cmd.Reset();
329
                        cmd.CommandText = string.Format(@"
330
                            SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
331
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
332
                            dt.Load(dr);
333

    
334
                        childList = childList.Distinct().ToList();
335
                        foreach (var child in childList)
336
                        {
337
                            string mappingPath = string.Empty;
338
                            DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
339
                            if (rows.Length == 1)
340
                                mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
341

    
342
                            DataRow newRow = result.NewRow();
343
                            newRow["UID"] = child;
344
                            newRow["Name"] = child;
345
                            newRow["Type"] = "Child Symbol";
346
                            newRow["SPPID_SYMBOL_PATH"] = mappingPath;
347
                            result.Rows.Add(newRow);
348
                        }
349
                    }
350
                    connection.Close();
351
                }
352
                catch (Exception ex)
353
                {
354

    
355
                }
356
                finally
357
                {
358
                    connection.Dispose();
359
                }
360
            }
361

    
362
            return result;
363
        }
364

    
365
        public static DataTable SelectProjectLine()
366
        {
367
            DataTable dt = new DataTable();
368
            Project_Info projectInfo = Project_Info.GetInstance();
369
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
370
            {
371
                try
372
                {
373
                    connection.Open();
374
                    using (SQLiteCommand cmd = connection.CreateCommand())
375
                    {
376
                        cmd.CommandText = string.Format(@"
377
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
378
                                LEFT OUTER JOIN {1} as sp 
379
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
380
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
381
                            dt.Load(dr);
382
                    }
383
                    connection.Close();
384
                }
385
                catch (Exception ex)
386
                {
387

    
388
                }
389
                finally
390
                {
391
                    connection.Dispose();
392
                }
393
            }
394

    
395
            return dt;
396
        }
397

    
398
        public static DataTable SelectProjectLineProperties()
399
        {
400
            DataTable dt = new DataTable();
401
            Project_Info projectInfo = Project_Info.GetInstance();
402
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
403
            {
404
                try
405
                {
406
                    connection.Open();
407
                    using (SQLiteCommand cmd = connection.CreateCommand())
408
                    {
409
                        cmd.CommandText = string.Format(@"
410
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
411
                            FROM {0} as lp 
412
                                 LEFT OUTER JOIN {1} as sp 
413
                                      ON lp.UID = sp.UID
414
                                 LEFT OUTER JOIN {2} as spa 
415
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
416
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
417
                            dt.Load(dr);
418
                    }
419
                    connection.Close();
420
                }
421
                catch (Exception ex)
422
                {
423

    
424
                }
425
                finally
426
                {
427
                    connection.Dispose();
428
                }
429
            }
430

    
431
            return dt;
432
        }
433

    
434
        public static DataTable SelectProjectAttribute()
435
        {
436
            DataTable dt = new DataTable();
437
            Project_Info projectInfo = Project_Info.GetInstance();
438
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
439
            {
440
                try
441
                {
442
                    connection.Open();
443
                    using (SQLiteCommand cmd = connection.CreateCommand())
444
                    {
445
                        cmd.CommandText = string.Format(@"
446
                            SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spl.LOCATION, spl.LEADERLINE, sa.Property
447
                            FROM {1} as sa, {0} as st 
448
                                 LEFT OUTER JOIN {2} as sp 
449
                                      ON sa.UID = SP.UID 
450
                                LEFT OUTER JOIN {3} as spa 
451
                                     ON sa.UID = spa.UID
452
                                LEFT OUTER JOIN {4} as spl 
453
                                     ON sa.UID = spl.UID
454
                            WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE);
455
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
456
                            dt.Load(dr);
457
                    }
458
                    connection.Close();
459
                }
460
                catch (Exception ex)
461
                {
462

    
463
                }
464
                finally
465
                {
466
                    connection.Dispose();
467
                }
468
            }
469

    
470
            return dt;
471
        }
472

    
473
        public static DataTable SelectID2SymbolTable()
474
        {
475
            DataTable dt = new DataTable();
476
            Project_Info projectInfo = Project_Info.GetInstance();
477
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
478
            {
479
                try
480
                {
481
                    connection.Open();
482
                    using (SQLiteCommand cmd = connection.CreateCommand())
483
                    {
484
                        cmd.CommandText = "SELECT * FROM Symbol";
485
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
486
                            dt.Load(dr);
487
                    }
488
                    connection.Close();
489
                }
490
                catch (Exception ex)
491
                {
492

    
493
                }
494
                finally
495
                {
496
                    connection.Dispose();
497
                }
498
            }
499

    
500
            return dt;
501
        }
502

    
503
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas)
504
        {
505
            Project_Info projectInfo = Project_Info.GetInstance();
506
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
507
            {
508
                try
509
                {
510
                    connection.Open();
511
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
512
                    {
513
                        try
514
                        {
515
                            using (SQLiteCommand cmd = connection.CreateCommand())
516
                            {
517
                                foreach (var item in datas)
518
                                {
519
                                    cmd.Parameters.Clear();
520
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE);
521
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
522
                                    cmd.Parameters.AddWithValue("@NAME", item.Item2);
523
                                    cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
524
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
525
                                    cmd.ExecuteNonQuery();
526
                                }
527
                            }
528
                            transaction.Commit();
529
                            connection.Close();
530
                        }
531
                        catch (Exception ex)
532
                        {
533
                            transaction.Rollback();
534
                        }
535
                        finally
536
                        {
537
                            transaction.Dispose();
538
                        }
539
                    }
540
                }
541
                catch (Exception ex)
542
                {
543
                    return false;
544
                }
545
                finally
546
                {
547
                    connection.Dispose();
548
                }
549
            }
550

    
551
            return true;
552
        }
553

    
554
        public static bool InsertAttributeMapping(List<Tuple<string, string>> datas)
555
        {
556
            Project_Info projectInfo = Project_Info.GetInstance();
557
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
558
            {
559
                try
560
                {
561
                    connection.Open();
562
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
563
                    {
564
                        try
565
                        {
566
                            using (SQLiteCommand cmd = connection.CreateCommand())
567
                            {
568
                                foreach (var item in datas)
569
                                {
570
                                    cmd.Parameters.Clear();
571
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE);
572
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
573
                                    cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
574
                                    cmd.ExecuteNonQuery();
575
                                }
576
                            }
577
                            transaction.Commit();
578
                            connection.Close();
579
                        }
580
                        catch (Exception ex)
581
                        {
582
                            transaction.Rollback();
583
                        }
584
                        finally
585
                        {
586
                            transaction.Dispose();
587
                        }
588
                    }
589
                }
590
                catch (Exception ex)
591
                {
592
                    return false;
593
                }
594
                finally
595
                {
596
                    connection.Dispose();
597
                }
598
            }
599
            return true;
600
        }
601

    
602
        public static bool InsertLabelInfoMapping(List<Tuple<string, int, bool>> datas)
603
        {
604
            Project_Info projectInfo = Project_Info.GetInstance();
605
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
606
            {
607
                try
608
                {
609
                    connection.Open();
610
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
611
                    {
612
                        try
613
                        {
614
                            using (SQLiteCommand cmd = connection.CreateCommand())
615
                            {
616
                                foreach (var item in datas)
617
                                {
618
                                    cmd.Parameters.Clear();
619
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE);
620
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
621
                                    cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
622
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
623
                                    cmd.ExecuteNonQuery();
624
                                }
625
                            }
626
                            transaction.Commit();
627
                            connection.Close();
628
                        }
629
                        catch (Exception ex)
630
                        {
631
                            transaction.Rollback();
632
                        }
633
                        finally
634
                        {
635
                            transaction.Dispose();
636
                        }
637
                    }
638
                }
639
                catch (Exception ex)
640
                {
641
                    return false;
642
                }
643
                finally
644
                {
645
                    connection.Dispose();
646
                }
647
            }
648
            return true;
649
        }
650

    
651
        public static bool InsertDrawingInfo()
652
        {
653
            Project_Info projectInfo = Project_Info.GetInstance();
654
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
655
            {
656
                try
657
                {
658
                    connection.Open();
659
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
660
                    {
661
                        try
662
                        {
663
                            //using (SQLiteCommand cmd = connection.CreateCommand())
664
                            //{
665
                            //    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE);
666
                            //    cmd.Parameters.AddWithValue("@UID", item.Item1);
667
                            //    cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
668
                            //    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
669
                            //    cmd.ExecuteNonQuery();
670
                            //}
671
                            //transaction.Commit();
672
                            //connection.Close();
673
                        }
674
                        catch (Exception ex)
675
                        {
676
                            transaction.Rollback();
677
                        }
678
                        finally
679
                        {
680
                            transaction.Dispose();
681
                        }
682
                    }
683
                }
684
                catch (Exception ex)
685
                {
686
                    return false;
687
                }
688
                finally
689
                {
690
                    connection.Dispose();
691
                }
692
            }
693
            return true;
694
        }
695
    }
696
}
클립보드 이미지 추가 (최대 크기: 500 MB)